2019-08-21 17:26:46 +00:00
# frozen_string_literal: true
2018-05-21 16:41:21 +00:00
# rubocop:disable Style/SignalException
require 'yaml'
2020-03-23 15:09:36 +00:00
SEE_DOC = " See [the documentation](https://docs.gitlab.com/ee/development/changelog.html). "
2019-08-21 17:26:46 +00:00
CREATE_CHANGELOG_MESSAGE = << ~ MSG
2020-03-23 15:09:36 +00:00
If you want to create a changelog entry for GitLab FOSS , run the following :
2018-07-10 10:10:54 +00:00
` ` `
2018-07-16 17:21:50 +00:00
bin / changelog - m %< mr_iid > s " %<mr_title>s "
2018-07-10 10:10:54 +00:00
` ` `
2019-09-17 14:16:34 +00:00
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 "
` ` `
2020-04-29 12:10:00 +00:00
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.
2018-07-10 10:10:54 +00:00
MSG
2020-03-23 15:09:36 +00:00
def check_changelog_yaml ( path )
2018-05-21 16:41:21 +00:00
yaml = YAML . safe_load ( File . read ( path ) )
2018-07-10 10:10:54 +00: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 16:41:21 +00:00
2020-01-04 00:07:49 +00:00
if yaml [ " merge_request " ] . nil? && ! helper . security_mr?
2018-07-10 10:10:54 +00:00
message " Consider setting `merge_request` to #{ gitlab . mr_json [ " iid " ] } in #{ gitlab . html_link ( path ) } . #{ SEE_DOC } "
2020-03-28 00:07:51 +00:00
elsif yaml [ " merge_request " ] != gitlab . mr_json [ " iid " ] && ! helper . security_mr?
2020-03-24 18:07:55 +00:00
fail " Merge request ID was not set to #{ gitlab . mr_json [ " iid " ] } ! #{ SEE_DOC } "
2018-05-21 16:41:21 +00:00
end
2018-07-13 03:08:45 +00:00
rescue Psych :: SyntaxError , Psych :: DisallowedClass , Psych :: BadAlias
2018-05-21 16:41:21 +00:00
# YAML could not be parsed, fail the build.
2018-07-10 10:10:54 +00:00
fail " #{ gitlab . html_link ( path ) } isn't valid YAML! #{ SEE_DOC } "
2018-07-13 03:08:45 +00:00
rescue StandardError = > e
warn " There was a problem trying to check the Changelog. Exception: #{ e . name } - #{ e . message } "
2018-05-21 16:41:21 +00:00
end
2020-03-23 15:09:36 +00: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
2020-01-16 18:08:46 +00:00
def sanitized_mr_title
helper . sanitize_mr_title ( gitlab . mr_json [ " title " ] )
end
2018-05-21 16:41:21 +00:00
if git . modified_files . include? ( " CHANGELOG.md " )
2018-07-16 17:21:50 +00:00
fail " **CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry. \n \n " +
2020-04-28 18:09:35 +00:00
format ( CREATE_CHANGELOG_MESSAGE , mr_iid : gitlab . mr_json [ " iid " ] , mr_title : sanitized_mr_title )
2018-05-21 16:41:21 +00:00
end
2019-12-12 15:08:41 +00:00
changelog_found = changelog . found
2020-03-23 15:09:36 +00:00
if changelog_found
check_changelog_yaml ( changelog_found )
check_changelog_path ( changelog_found )
elsif changelog . needed?
2020-04-29 12:10:00 +00:00
message " **[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html)**: \n \n " +
2020-04-28 18:09:35 +00:00
format ( CREATE_CHANGELOG_MESSAGE , mr_iid : gitlab . mr_json [ " iid " ] , mr_title : sanitized_mr_title )
2018-05-21 16:41:21 +00:00
end