Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Okstad <pokstad@gitlab.com>2020-06-05 00:07:00 +0300
committerPaul Okstad <pokstad@gitlab.com>2020-06-05 00:07:00 +0300
commit3df977c42349f95076ed6de8fc3ddcd60543075d (patch)
tree0503c6c9466caf20bab589a662a7a46e0128cd01
parent54195f2378d8c38502a88f0717ad6cd0100d57a5 (diff)
parent65c94270d715c8fc2bad20c3c2c622bd1f5019d2 (diff)
Merge branch 'zj-suggest-mr-iid-changelog' into 'master'
danger: Suggest merge request ID in the changelog See merge request gitlab-org/gitaly!2254
-rw-r--r--changelogs/unreleased/zj-suggest-mr-iid-changelog.yml5
-rw-r--r--danger/changelog/Dangerfile40
2 files changed, 30 insertions, 15 deletions
diff --git a/changelogs/unreleased/zj-suggest-mr-iid-changelog.yml b/changelogs/unreleased/zj-suggest-mr-iid-changelog.yml
new file mode 100644
index 000000000..1857a4ada
--- /dev/null
+++ b/changelogs/unreleased/zj-suggest-mr-iid-changelog.yml
@@ -0,0 +1,5 @@
+---
+title: 'danger: Suggest merge request ID in the changelog'
+merge_request: 2254
+author:
+type: other
diff --git a/danger/changelog/Dangerfile b/danger/changelog/Dangerfile
index 0273ab0e5..3fa83b39d 100644
--- a/danger/changelog/Dangerfile
+++ b/danger/changelog/Dangerfile
@@ -1,8 +1,9 @@
+# frozen_string_literal: true
require 'yaml'
NO_CHANGELOG_LABELS = %w[backstage documentation test].freeze
-SEE_DOC = "See [the documentation](https://gitlab.com/gitlab-org/gitaly/blob/master/CONTRIBUTING.md#changelog)".freeze
-CREATE_CHANGELOG_MESSAGE = <<~MSG.freeze
+SEE_DOC = "See the [changelog documentation](https://docs.gitlab.com/ee/development/changelog.html)."
+CREATE_CHANGELOG_MESSAGE = <<~MSG
You can create one with:
```
@@ -13,21 +14,32 @@ If your merge request doesn't warrant a CHANGELOG entry,
consider adding any of the %<labels>s labels.
MSG
+SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT
+```suggestion
+merge_request: %<mr_iid>s
+```
+
+#{SEE_DOC}
+SUGGEST_COMMENT
+
def check_changelog(path)
- yaml = YAML.load_file(path)
+ raw_file = File.read(path)
+ yaml = YAML.safe_load(raw_file)
fail "`title` should be set, in #{gitlab.html_link(path)}! #{SEE_DOC}" if yaml["title"].nil?
fail "`type` should be set, in #{gitlab.html_link(path)}! #{SEE_DOC}" if yaml["type"].nil?
if yaml["merge_request"].nil?
- message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{gitlab.html_link(path)}. #{SEE_DOC}"
+ mr_line = raw_file.lines.find_index { |l| l.start_with?("merge_request:") }
+
+ if mr_line
+ markdown(format(SUGGEST_MR_COMMENT, mr_iid: gitlab.mr_json["iid"]), file: path, line: mr_line.succ)
+ else
+ message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{gitlab.html_link(path)}. #{SEE_DOC}"
+ end
elsif yaml["merge_request"] != gitlab.mr_json["iid"]
fail "Merge request ID was not set to #{gitlab.mr_json["iid"]}! #{SEE_DOC}"
end
-
- if yaml["type"].nil?
- fail "No type was set in the changelog"
- end
rescue Psych::SyntaxError, Psych::DisallowedClass, Psych::BadAlias
# YAML could not be parsed, fail the build.
fail "#{gitlab.html_link(path)} isn't valid YAML! #{SEE_DOC}"
@@ -49,13 +61,11 @@ if git.modified_files.include?("CHANGELOG.md")
format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: mr_title, labels: presented_no_changelog_labels)
end
-if changelog_needed
- if changelog_found
- check_changelog(changelog_found)
- else
- warn "**[CHANGELOG missing](https://docs.gitlab.com/ce/development/changelog.html).**\n\n" +
- format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: mr_title, labels: presented_no_changelog_labels)
- end
+if changelog_found
+ check_changelog(changelog_found)
+elsif changelog_needed
+ warn "**[CHANGELOG missing](https://docs.gitlab.com/ce/development/changelog.html).**\n\n" +
+ format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: mr_title, labels: presented_no_changelog_labels)
end
# vim: ft=ruby