2019-08-21 13:26:46 -04:00
|
|
|
# frozen_string_literal: true
|
2018-05-21 12:41:21 -04:00
|
|
|
# rubocop:disable Style/SignalException
|
|
|
|
|
|
|
|
require 'yaml'
|
|
|
|
|
2020-05-27 08:08:19 -04:00
|
|
|
SEE_DOC = "See the [changelog documentation](https://docs.gitlab.com/ee/development/changelog.html)."
|
2018-07-10 06:10:54 -04:00
|
|
|
|
2020-05-27 08:08:19 -04:00
|
|
|
SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT
|
|
|
|
```suggestion
|
|
|
|
merge_request: %<mr_iid>s
|
|
|
|
```
|
|
|
|
|
|
|
|
#{SEE_DOC}
|
|
|
|
SUGGEST_COMMENT
|
|
|
|
|
2020-03-23 11:09:36 -04:00
|
|
|
def check_changelog_yaml(path)
|
2020-05-27 08:08:19 -04:00
|
|
|
raw_file = File.read(path)
|
|
|
|
yaml = YAML.safe_load(raw_file)
|
2018-05-21 12:41:21 -04:00
|
|
|
|
2018-07-10 06:10:54 -04:00
|
|
|
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?
|
2018-05-21 12:41:21 -04:00
|
|
|
|
2020-07-02 20:09:23 -04:00
|
|
|
return if helper.security_mr?
|
|
|
|
|
|
|
|
cherry_pick_against_stable_branch = helper.cherry_pick_mr? && helper.stable_branch?
|
|
|
|
|
|
|
|
if yaml["merge_request"].nil?
|
2020-05-27 08:08:19 -04:00
|
|
|
mr_line = raw_file.lines.find_index("merge_request:\n")
|
|
|
|
|
|
|
|
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
|
2020-07-02 20:09:23 -04:00
|
|
|
elsif yaml["merge_request"] != gitlab.mr_json["iid"] && !cherry_pick_against_stable_branch
|
2020-03-24 14:07:55 -04:00
|
|
|
fail "Merge request ID was not set to #{gitlab.mr_json["iid"]}! #{SEE_DOC}"
|
2018-05-21 12:41:21 -04:00
|
|
|
end
|
2018-07-12 23:08:45 -04:00
|
|
|
rescue Psych::SyntaxError, Psych::DisallowedClass, Psych::BadAlias
|
2018-05-21 12:41:21 -04:00
|
|
|
# YAML could not be parsed, fail the build.
|
2018-07-10 06:10:54 -04:00
|
|
|
fail "#{gitlab.html_link(path)} isn't valid YAML! #{SEE_DOC}"
|
2018-07-12 23:08:45 -04:00
|
|
|
rescue StandardError => e
|
2020-07-01 05:09:30 -04:00
|
|
|
warn "There was a problem trying to check the Changelog. Exception: #{e.class.name} - #{e.message}"
|
2018-05-21 12:41:21 -04:00
|
|
|
end
|
|
|
|
|
2020-03-23 11:09:36 -04:00
|
|
|
def check_changelog_path(path)
|
|
|
|
ee_changes = helper.all_ee_changes.dup
|
|
|
|
ee_changes.delete(path)
|
|
|
|
|
|
|
|
if ee_changes.any? && !changelog.ee_changelog?
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2018-05-21 12:41:21 -04:00
|
|
|
if git.modified_files.include?("CHANGELOG.md")
|
2020-08-20 23:10:16 -04:00
|
|
|
fail changelog.modified_text
|
2018-05-21 12:41:21 -04:00
|
|
|
end
|
|
|
|
|
2019-12-12 10:08:41 -05:00
|
|
|
changelog_found = changelog.found
|
|
|
|
|
2020-03-23 11:09:36 -04:00
|
|
|
if changelog_found
|
|
|
|
check_changelog_yaml(changelog_found)
|
|
|
|
check_changelog_path(changelog_found)
|
2020-08-20 23:10:16 -04:00
|
|
|
elsif changelog.required?
|
|
|
|
fail changelog.required_text
|
|
|
|
elsif changelog.optional?
|
|
|
|
message changelog.optional_text
|
2018-05-21 12:41:21 -04:00
|
|
|
end
|