diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2020-06-05 00:06:59 +0300 |
---|---|---|
committer | Paul Okstad <pokstad@gitlab.com> | 2020-06-05 00:06:59 +0300 |
commit | 65c94270d715c8fc2bad20c3c2c622bd1f5019d2 (patch) | |
tree | 5f828ab4e88d12c82b072e545cae29e5d6bbb429 /danger | |
parent | 7f816096055be4fcde75606811b30c2121ff8487 (diff) |
danger: Suggest merge request ID in the changelog
When creating a changelog entry, there's a slightly award dance where
the changelog entry needs to contain a merge request id which is unknown
at the time of generation. This create the situation where either a
developer guesses the next MR ID or has to create the MR, update the
changelog entry, and push again.
This change lets @GitalyBot suggest the MR ID, which can be applied by
the developer. Squashing the commit is left to the developer to do.
Diffstat (limited to 'danger')
-rw-r--r-- | danger/changelog/Dangerfile | 40 |
1 files changed, 25 insertions, 15 deletions
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 |