summaryrefslogtreecommitdiff
path: root/danger/changelog
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-05-21 18:41:21 +0200
committerRémy Coutable <remy@rymai.me>2018-07-11 11:52:01 +0200
commit5679837cd412c2fb7911dcb33c19e89d8a787db0 (patch)
treefe9984ff05042df9ec0fc6de59e85171e337866d /danger/changelog
parentd2ea56a87026de92f31bbcfb360748fcf766b835 (diff)
downloadgitlab-ce-5679837cd412c2fb7911dcb33c19e89d8a787db0.tar.gz
Start to use Danger for automating MR reviews
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'danger/changelog')
-rw-r--r--danger/changelog/Dangerfile39
1 files changed, 39 insertions, 0 deletions
diff --git a/danger/changelog/Dangerfile b/danger/changelog/Dangerfile
new file mode 100644
index 00000000000..773ffa15a0f
--- /dev/null
+++ b/danger/changelog/Dangerfile
@@ -0,0 +1,39 @@
+# rubocop:disable Style/SignalException
+
+require 'yaml'
+
+def check_changelog(path)
+ yaml = YAML.safe_load(File.read(path))
+
+ fail "`title` should be set, in #{gitlab.html_link(path)}." if yaml["title"].nil?
+ fail "`type` should be set, in #{gitlab.html_link(path)}." if yaml["type"].nil?
+
+ if yaml["merge_request"].nil?
+ message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{gitlab.html_link(path)}."
+ elsif yaml["merge_request"] != gitlab.mr_json["iid"]
+ fail "Merge request IID was not set to #{gitlab.mr_json["iid"]}!"
+ end
+rescue StandardError
+ # YAML could not be parsed, fail the build.
+ fail "#{gitlab.html_link(path)} isn't valid YAML!"
+end
+
+changelog_needed = !gitlab.mr_labels.include?("backstage")
+changelog_found = git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} }
+
+if git.modified_files.include?("CHANGELOG.md")
+ fail "CHANGELOG.md was edited. Please remove the additions and create an entry with `bin/changelog -m #{gitlab.mr_json["iid"]}` instead."
+end
+
+if changelog_needed
+ if changelog_found
+ check_changelog(path)
+ else
+ msg = [
+ "This merge request is missing a CHANGELOG entry, you can create one with `bin/changelog -m #{gitlab.mr_json["iid"]}`.",
+ "If your merge request doesn't warrant a CHANGELOG entry, consider adding the ~backstage label."
+ ]
+
+ warn msg.join(" ")
+ end
+end