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:
authorJohn Cai <jcai@gitlab.com>2019-02-28 23:17:49 +0300
committerJohn Cai <jcai@gitlab.com>2019-02-28 23:17:49 +0300
commit2e30fbbd8286669b6148c2c191eec08c36ffa263 (patch)
treee5dd484a63f6d4d419d37a40c218a79e76ceab3c
parent96b61ee054553af78f564eec5a0f7d839a3d50d1 (diff)
parent9a36582c77764f12173261a3476cda2446e54e33 (diff)
Merge branch 'zj-danger-label-apply' into 'master'
Use danger to apply labels to MRs See merge request gitlab-org/gitaly!1105
-rw-r--r--Dangerfile44
-rw-r--r--changelogs/unreleased/zj-danger-label-apply.yml5
-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
6 files changed, 141 insertions, 40 deletions
diff --git a/Dangerfile b/Dangerfile
index f1bb16150..a06699f6c 100644
--- a/Dangerfile
+++ b/Dangerfile
@@ -1,42 +1,6 @@
-require 'yaml'
-require 'json'
-
-fail("Please provide a MR description") if gitlab.mr_body.empty?
-
-def check_changelog(path)
- if git.modified_files.include?("CHANGELOG.md")
- fail("CHANGELOG.md was edited. Please remove the additions and create an entry with _support/changelog")
- return
- end
-
- if !git.added_files.include?(path)
- warn("No changelog entry was generated, please do so by executing _support/changelog")
- else
- yaml = YAML.safe_load(File.read(path))
-
- unless yaml['merge_request'] == gitlab.mr_json["iid"]
- fail("Merge request ID was not set to #{gitlab.mr_json['iid']}")
- end
-
- unless yaml['title'] == gitlab.mr_title
- fail('Changelog entry should match the MR title')
- end
- end
-end
-
-check_changelog(File.join('changelogs', 'unreleased', "#{gitlab.branch_for_head}.yml"))
-
-VENDOR_JSON = 'vendor/vendor.json'
-fail("Expected #{VENDOR_JSON} to exist") unless File.exist?(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
+danger.import_dangerfile(path: 'danger/changelog')
+danger.import_dangerfile(path: 'danger/govendor_proto_check')
+danger.import_dangerfile(path: 'danger/labels')
+danger.import_dangerfile(path: 'danger/merge_request')
# vim: ft=ruby
diff --git a/changelogs/unreleased/zj-danger-label-apply.yml b/changelogs/unreleased/zj-danger-label-apply.yml
new file mode 100644
index 000000000..104b09270
--- /dev/null
+++ b/changelogs/unreleased/zj-danger-label-apply.yml
@@ -0,0 +1,5 @@
+---
+title: GitalyBot will apply labels to merge requests
+merge_request: 1105
+author:
+type: other
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