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
path: root/danger
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2019-02-27 22:57:53 +0300
committerZeger-Jan van de Weg <git@zjvandeweg.nl>2019-02-28 13:57:21 +0300
commit9a36582c77764f12173261a3476cda2446e54e33 (patch)
tree0161ba6c2dbc81687eb813f08c9a08a4a586cd38 /danger
parentd92c70a3e87a9fabccdbff5e88548b62e4f77efb (diff)
Have GitalyBot apply labels throught Danger
Using Danger a small rule book, @GitalyBot will apply labels and have a few more rules on the changelog.
Diffstat (limited to 'danger')
-rw-r--r--danger/changelog/Dangerfile60
-rw-r--r--danger/govendor_proto_check/Dangerfile15
-rw-r--r--danger/labels/Dangerfile40
-rw-r--r--danger/merge_request/Dangerfile17
4 files changed, 132 insertions, 0 deletions
diff --git a/danger/changelog/Dangerfile b/danger/changelog/Dangerfile
new file mode 100644
index 000000000..af8e6b93d
--- /dev/null
+++ b/danger/changelog/Dangerfile
@@ -0,0 +1,60 @@
+require 'yaml'
+
+NO_CHANGELOG_LABELS = %w[backstage Documentation test].freeze
+CREATE_CHANGELOG_MESSAGE = <<~MSG.freeze
+You can create one with:
+
+```
+_support/changelog -m %<mr_iid>s "%<mr_title>s"
+```
+
+If your merge request doesn't warrant a CHANGELOG entry,
+consider adding any of the %<labels>s labels.
+MSG
+
+def check_changelog(path)
+ yaml = YAML.safe_load(File.read(path))
+
+ 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}"
+ 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}"
+rescue StandardError => e
+ warn "There was a problem trying to check the Changelog. Exception: #{e.name} - #{e.message}"
+end
+
+def presented_no_changelog_labels
+ NO_CHANGELOG_LABELS.map { |label| "~#{label}" }.join(', ')
+end
+
+changelog_needed = (gitlab.mr_labels & NO_CHANGELOG_LABELS).empty?
+changelog_found = git.added_files.find { |path| path =~ %r{\Achangelogs/unreleased/} }
+
+mr_title = gitlab.mr_json["title"].gsub(/^WIP: */, '')
+
+if git.modified_files.include?("CHANGELOG.md")
+ fail "**CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry.\n\n" +
+ 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
+end
+
+# vim: ft=ruby
diff --git a/danger/govendor_proto_check/Dangerfile b/danger/govendor_proto_check/Dangerfile
new file mode 100644
index 000000000..9f186fc4b
--- /dev/null
+++ b/danger/govendor_proto_check/Dangerfile
@@ -0,0 +1,15 @@
+require 'json'
+
+VENDOR_JSON = 'vendor/vendor.json'
+
+if git.modified_files.include?(VENDOR_JSON)
+ parsed_json = JSON.parse(File.read(VENDOR_JSON))
+
+ proto = parsed_json["package"]&.find { |h| h["path"].start_with?("gitlab.com/gitlab-org/gitaly-proto") }
+
+ unless proto["version"] && proto["version"] =~ /\Av\d+\./
+ fail("gitaly-proto version is incorrect")
+ end
+end
+
+# vim: ft=ruby
diff --git a/danger/labels/Dangerfile b/danger/labels/Dangerfile
new file mode 100644
index 000000000..9839b797c
--- /dev/null
+++ b/danger/labels/Dangerfile
@@ -0,0 +1,40 @@
+def changelog_entry
+ @changelog_entry ||=
+ begin
+ file = git.added_files.find { |path| path =~ %r{\Achangelogs/unreleased/} }
+
+ YAML.safe_load(File.read(file))
+ rescue
+ # The changelog danger file will handle this
+ {}
+ end
+end
+
+required_labels = []
+
+GITALY_TEAM = %w[jacobvosmaer-gitlab johncai pokstad1 zj]
+
+if GITALY_TEAM.include?(gitlab.mr_author) && !gitlab.mr_labels.include?("Gitaly")
+ required_labels << "Gitaly"
+end
+
+TYPE_TO_LABEL = {
+ 'added' => 'feature',
+ 'fixed' => 'bug',
+ 'changed' => 'backstage',
+ 'deprecated' => 'backstage',
+ 'security' => 'security',
+ 'removed' => 'backstage',
+ 'performance' => 'performance',
+ 'other' => 'backstage',
+}
+
+required_labels << TYPE_TO_LABEL[changelog_entry["type"]]
+
+gitlab.api.update_merge_request(
+ gitlab.mr_json['project_id'],
+ gitlab.mr_json['iid'],
+ labels: (gitlab.mr_labels | required_labels).join(",")
+)
+
+# vim: ft=ruby
diff --git a/danger/merge_request/Dangerfile b/danger/merge_request/Dangerfile
new file mode 100644
index 000000000..c69204936
--- /dev/null
+++ b/danger/merge_request/Dangerfile
@@ -0,0 +1,17 @@
+unless gitlab.mr_title[0] == gitlab.mr_title[0].upcase
+ warn("Please capitalize the merge request title")
+end
+
+if gitlab.mr_body.empty?
+ fail("Please provide a merge request description")
+end
+
+unless gitlab.mr_json["assignee"]
+ warn "This merge request does not have any assignee yet. Setting an assignee clarifies who needs to take action on the merge request at any given time."
+end
+
+if gitlab.mr_title.length > 72
+ warn "The title of this merge requests it too long"
+end
+
+# vim: ft=ruby