debian-mirror-gitlab/danger/changelog/Dangerfile

100 lines
3.9 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2018-11-18 11:00:15 +05:30
# rubocop:disable Style/SignalException
require 'yaml'
2020-06-23 00:09:42 +05:30
SEE_DOC = "See the [changelog documentation](https://docs.gitlab.com/ee/development/changelog.html)."
2018-11-18 11:00:15 +05:30
2020-06-23 00:09:42 +05:30
SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT
```suggestion
merge_request: %<mr_iid>s
```
#{SEE_DOC}
SUGGEST_COMMENT
2020-04-22 19:07:51 +05:30
def check_changelog_yaml(path)
2020-06-23 00:09:42 +05:30
raw_file = File.read(path)
yaml = YAML.safe_load(raw_file)
2018-11-18 11:00:15 +05:30
2021-04-17 20:07:23 +05:30
fail "`title` should be set, in #{helper.html_link(path)}! #{SEE_DOC}" if yaml["title"].nil?
fail "`type` should be set, in #{helper.html_link(path)}! #{SEE_DOC}" if yaml["type"].nil?
2018-11-18 11:00:15 +05:30
2020-07-28 23:09:34 +05:30
return if helper.security_mr?
2021-04-29 21:17:54 +05:30
return if helper.mr_iid.to_s.empty?
2020-07-28 23:09:34 +05:30
cherry_pick_against_stable_branch = helper.cherry_pick_mr? && helper.stable_branch?
if yaml["merge_request"].nil?
2020-06-23 00:09:42 +05:30
mr_line = raw_file.lines.find_index("merge_request:\n")
if mr_line
2021-04-29 21:17:54 +05:30
markdown(format(SUGGEST_MR_COMMENT, mr_iid: helper.mr_iid), file: path, line: mr_line.succ)
2020-06-23 00:09:42 +05:30
else
2021-04-29 21:17:54 +05:30
message "Consider setting `merge_request` to #{helper.mr_iid} in #{helper.html_link(path)}. #{SEE_DOC}"
2020-06-23 00:09:42 +05:30
end
2021-04-29 21:17:54 +05:30
elsif yaml["merge_request"] != helper.mr_iid && !cherry_pick_against_stable_branch
fail "Merge request ID was not set to #{helper.mr_iid}! #{SEE_DOC}"
2018-11-18 11:00:15 +05:30
end
2021-03-11 19:13:27 +05:30
rescue Psych::Exception
2018-11-18 11:00:15 +05:30
# YAML could not be parsed, fail the build.
2021-04-17 20:07:23 +05:30
fail "#{helper.html_link(path)} isn't valid YAML! #{SEE_DOC}"
2018-11-18 11:00:15 +05:30
rescue StandardError => e
2020-07-28 23:09:34 +05:30
warn "There was a problem trying to check the Changelog. Exception: #{e.class.name} - #{e.message}"
2018-11-18 11:00:15 +05:30
end
2020-04-22 19:07:51 +05:30
def check_changelog_path(path)
2021-04-17 20:07:23 +05:30
ee_changes = project_helper.all_ee_changes.dup
2020-04-22 19:07:51 +05:30
ee_changes.delete(path)
2021-04-17 20:07:23 +05:30
if ee_changes.any? && !changelog.ee_changelog? && !changelog.required?
2020-04-22 19:07:51 +05:30
warn "This MR has a Changelog file outside `ee/`, but code changes in `ee/`. Consider moving the Changelog file into `ee/`."
end
if ee_changes.empty? && changelog.ee_changelog?
warn "This MR has a Changelog file in `ee/`, but no code changes in `ee/`. Consider moving the Changelog file outside `ee/`."
end
2021-02-22 17:27:13 +05:30
2021-04-17 20:07:23 +05:30
if ee_changes.any? && changelog.ee_changelog? && changelog.required_reasons.include?(:db_changes)
2021-02-22 17:27:13 +05:30
warn "This MR has a Changelog file inside `ee/`, but there are database changes which [requires](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry) the Changelog placement to be outside of `ee/`. Consider moving the Changelog file outside `ee/`."
end
2020-04-22 19:07:51 +05:30
end
2018-11-18 11:00:15 +05:30
if git.modified_files.include?("CHANGELOG.md")
2020-11-24 15:15:51 +05:30
fail changelog.modified_text
2018-11-18 11:00:15 +05:30
end
2020-01-01 13:55:28 +05:30
changelog_found = changelog.found
2020-04-22 19:07:51 +05:30
if changelog_found
check_changelog_yaml(changelog_found)
check_changelog_path(changelog_found)
2020-11-24 15:15:51 +05:30
elsif changelog.required?
2021-04-17 20:07:23 +05:30
changelog.required_texts.each { |_, text| fail(text) } # rubocop:disable Lint/UnreachableLoop
2020-11-24 15:15:51 +05:30
elsif changelog.optional?
message changelog.optional_text
2018-11-18 11:00:15 +05:30
end
2021-04-29 21:17:54 +05:30
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