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'
2019-12-04 20:38:33 +05:30
SEE_DOC = " See [the documentation](https://docs.gitlab.com/ce/development/changelog.html). "
CREATE_CHANGELOG_MESSAGE = << ~ MSG
2018-11-18 11:00:15 +05:30
You can create one with :
` ` `
bin / changelog - m %< mr_iid > s " %<mr_title>s "
` ` `
2019-12-04 20:38:33 +05:30
If you want to create a changelog entry for GitLab EE , run the following instead :
` ` `
bin / changelog - - ee - m %< mr_iid > s " %<mr_title>s "
` ` `
Note : Merge requests with %< labels > s do not trigger this check .
2018-11-18 11:00:15 +05:30
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 } "
2020-01-01 13:55:28 +05:30
elsif yaml [ " merge_request " ] != gitlab . mr_json [ " iid " ] && ! changelog . ce_port_changelog? ( path )
2018-11-18 11:00:15 +05:30
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 git . modified_files . include? ( " CHANGELOG.md " )
fail " **CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry. \n \n " +
2020-01-01 13:55:28 +05:30
format ( CREATE_CHANGELOG_MESSAGE , mr_iid : gitlab . mr_json [ " iid " ] , mr_title : changelog . sanitized_mr_title , labels : changelog . presented_no_changelog_labels )
2018-11-18 11:00:15 +05:30
end
2020-01-01 13:55:28 +05:30
changelog_found = changelog . found
if changelog . needed?
2018-11-18 11:00:15 +05:30
if changelog_found
check_changelog ( changelog_found )
else
2019-12-04 20:38:33 +05:30
message " **[CHANGELOG missing](https://docs.gitlab.com/ce/development/changelog.html)**: If this merge request [doesn't need a CHANGELOG entry](https://docs.gitlab.com/ee/development/changelog.html # what-warrants-a-changelog-entry), feel free to ignore this message. \n \n " +
2020-01-01 13:55:28 +05:30
format ( CREATE_CHANGELOG_MESSAGE , mr_iid : gitlab . mr_json [ " iid " ] , mr_title : changelog . sanitized_mr_title , labels : changelog . presented_no_changelog_labels )
2018-11-18 11:00:15 +05:30
end
end