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:
authorYorick Peterse <yorick@yorickpeterse.com>2021-05-18 18:07:56 +0300
committerYorick Peterse <yorick@yorickpeterse.com>2021-05-21 16:54:49 +0300
commitbe63f02ea121c07e0b4a55ee8fa37a418d41ceb5 (patch)
treed3a87d8390c41aaa3804b144839c956fe8f13801 /danger
parent98b62a8e6b2b87ad6fbfb70f706274ee91e953d8 (diff)
Update tooling for the new changelog workflow
Similar to https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62012, this updates Gitaly's CI tooling for the new changelog workflow.
Diffstat (limited to 'danger')
-rw-r--r--danger/changelog/Dangerfile141
1 files changed, 43 insertions, 98 deletions
diff --git a/danger/changelog/Dangerfile b/danger/changelog/Dangerfile
index 1a7029768..56efe44de 100644
--- a/danger/changelog/Dangerfile
+++ b/danger/changelog/Dangerfile
@@ -1,33 +1,33 @@
-# frozen_string_literal: true
require 'yaml'
+def lint_commit(commit)
+ trailer = commit.message.match(/^Changelog:\s*(?<category>\w+)/)
+
+ return :missing if trailer.nil? || trailer[:category].nil?
+
+ category = trailer[:category]
+
+ return :valid if CATEGORIES.include?(category)
+
+ self.fail(
+ "Commit #{commit.sha} uses an invalid changelog category: #{category}"
+ )
+
+ :invalid
+end
+
+def presented_no_changelog_labels
+ NO_CHANGELOG_LABELS.map { |label| %(~"#{label}") }.join(', ')
+end
+
NO_CHANGELOG_LABELS = [
+ 'documentation',
'tooling',
'tooling::pipelines',
'tooling::workflow',
'ci-build',
- 'meta',
- 'documentation'
+ 'meta'
].freeze
-SEE_DOC = "See the [changelog documentation](https://docs.gitlab.com/ee/development/changelog.html)."
-CREATE_CHANGELOG_MESSAGE = <<~MSG
-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
-
-SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT
-```suggestion
-merge_request: %<mr_iid>s
-```
-
-#{SEE_DOC}
-SUGGEST_COMMENT
CATEGORIES = YAML
.load_file(File.expand_path('../../.gitlab/changelog_config.yml', __dir__))
@@ -35,102 +35,47 @@ CATEGORIES = YAML
.keys
.freeze
-def check_changelog_trailer(commit)
- trailer = commit.message.match(/^Changelog:\s*(?<category>.+)$/)
+SEE_DOC = "See [the documentation](https://docs.gitlab.com/ee/development/changelog.html).".freeze
- return :missing if trailer.nil? || trailer[:category].nil?
+CHANGELOG_MISSING = <<~MSG.freeze
+**[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html).**
- category = trailer[:category]
+To ceate a changelog, annotate one or more commits with the `Changelog` Git
+trailer. If you want to annotate the latest commit, you can do so using `git
+commit --amend`. If you want to annotate older or multiple commits, you need to
+do so using `git rebase -i`.
- return :valid if CATEGORIES.include?(category)
+When adding the trailer, you can use the following values:
- self.fail(
- "Commit #{commit.sha} uses an invalid changelog category: #{category}"
- )
+- #{CATEGORIES.join("\n- ")}
- :invalid
-end
+For example:
-def check_changelog(path)
- raw_file = File.read(path)
- yaml = YAML.safe_load(raw_file)
+```
+This is the subject of your commit.
- 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?
+This would be the body of your commit containing some extra details.
- if yaml["merge_request"].nil?
- mr_line = raw_file.lines.find_index { |l| l.start_with?("merge_request:") }
+Changelog: added
+```
- 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
-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
+If your merge request doesn't warrant a CHANGELOG entry, consider adding any of
+the #{presented_no_changelog_labels} labels.
-def presented_no_changelog_labels
- NO_CHANGELOG_LABELS.map { |label| %Q(~\\"#{label}\\") }.join(', ')
-end
+#{SEE_DOC}
+MSG
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_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
if changelog_needed
checked = 0
git.commits.each do |commit|
- case check_changelog_trailer(commit)
+ case lint_commit(commit)
when :valid, :invalid
checked += 1
end
end
- if checked == 0
- message <<~MSG
- We are in the process of rolling out a new workflow for adding changelog entries. This new workflow uses Git commit subjects and Git trailers to generate changelogs. This new approach will soon replace the current YAML based approach.
-
- To ease the transition process, we recommend you start using both the old and new approach in parallel. This is not required at this time, but will make it easier to transition to the new approach in the future. To do so, pick the commit that should go in the changelog and add a `Changelog` trailer to it. For example:
-
- ```
- This is my commit's subject line
-
- This is the optional commit body.
-
- Changelog: added
- ```
-
- The value of the `Changelog` trailer should be one of the following: added, fixed, changed, deprecated, removed, security, performance, other.
-
- For more information, take a look at the following resources:
-
- - `https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1564`
- - https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data
-
- If you'd like to see the new approach in action, take a look at the commits in [the Omnibus repository](https://gitlab.com/gitlab-org/omnibus-gitlab/-/commits/master).
- MSG
- end
+ warn(CHANGELOG_MISSING) if checked.zero?
end
-
-# vim: ft=ruby