2018-05-21 12:41:21 -04:00
|
|
|
# rubocop:disable Style/SignalException
|
|
|
|
|
|
|
|
require 'yaml'
|
|
|
|
|
2018-12-04 11:57:41 -05:00
|
|
|
NO_CHANGELOG_LABELS = %w[backstage ci-build Documentation meta QA test].freeze
|
2018-07-11 15:44:35 -04:00
|
|
|
SEE_DOC = "See [the documentation](https://docs.gitlab.com/ce/development/changelog.html).".freeze
|
2018-07-16 13:21:50 -04:00
|
|
|
CREATE_CHANGELOG_MESSAGE = <<~MSG.freeze
|
2018-07-10 06:10:54 -04:00
|
|
|
You can create one with:
|
|
|
|
|
|
|
|
```
|
2018-07-16 13:21:50 -04:00
|
|
|
bin/changelog -m %<mr_iid>s "%<mr_title>s"
|
2018-07-10 06:10:54 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
If your merge request doesn't warrant a CHANGELOG entry,
|
|
|
|
consider adding any of the %<labels>s labels.
|
|
|
|
#{SEE_DOC}
|
|
|
|
MSG
|
|
|
|
|
|
|
|
def ee?
|
|
|
|
ENV['CI_PROJECT_NAME'] == 'gitlab-ee' || File.exist?('../../CHANGELOG-EE.md')
|
|
|
|
end
|
|
|
|
|
|
|
|
def ee_changelog?(changelog_path)
|
|
|
|
changelog_path =~ /unreleased-ee/
|
|
|
|
end
|
|
|
|
|
|
|
|
def ce_port_changelog?(changelog_path)
|
|
|
|
ee? && !ee_changelog?(changelog_path)
|
|
|
|
end
|
|
|
|
|
2018-05-21 12:41:21 -04:00
|
|
|
def check_changelog(path)
|
|
|
|
yaml = YAML.safe_load(File.read(path))
|
|
|
|
|
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
|
|
|
|
|
|
|
if yaml["merge_request"].nil?
|
2018-07-10 06:10:54 -04:00
|
|
|
message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{gitlab.html_link(path)}. #{SEE_DOC}"
|
2018-07-12 23:08:45 -04:00
|
|
|
elsif yaml["merge_request"] != gitlab.mr_json["iid"] && !ce_port_changelog?(path)
|
2018-07-10 06:10:54 -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
|
|
|
|
warn "There was a problem trying to check the Changelog. Exception: #{e.name} - #{e.message}"
|
2018-05-21 12:41:21 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 06:10:54 -04:00
|
|
|
def presented_no_changelog_labels
|
|
|
|
NO_CHANGELOG_LABELS.map { |label| "~#{label}" }.join(', ')
|
|
|
|
end
|
|
|
|
|
|
|
|
changelog_needed = (gitlab.mr_labels & NO_CHANGELOG_LABELS).empty?
|
2018-05-21 12:41:21 -04:00
|
|
|
changelog_found = git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} }
|
|
|
|
|
2018-08-24 16:54:55 -04:00
|
|
|
mr_title = gitlab.mr_json["title"].gsub(/^WIP: */, '')
|
|
|
|
|
2018-05-21 12:41:21 -04:00
|
|
|
if git.modified_files.include?("CHANGELOG.md")
|
2018-07-16 13:21:50 -04:00
|
|
|
fail "**CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry.\n\n" +
|
2018-08-24 16:54:55 -04:00
|
|
|
format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: mr_title, labels: presented_no_changelog_labels)
|
2018-05-21 12:41:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if changelog_needed
|
|
|
|
if changelog_found
|
2018-07-12 04:16:16 -04:00
|
|
|
check_changelog(changelog_found)
|
2018-05-21 12:41:21 -04:00
|
|
|
else
|
2018-07-16 13:21:50 -04:00
|
|
|
warn "**[CHANGELOG missing](https://docs.gitlab.com/ce/development/changelog.html).**\n\n" +
|
2018-08-24 16:54:55 -04:00
|
|
|
format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: mr_title, labels: presented_no_changelog_labels)
|
2018-05-21 12:41:21 -04:00
|
|
|
end
|
|
|
|
end
|