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). "
2019-12-04 20:38:33 +05:30
CREATE_CHANGELOG_MESSAGE = << ~ MSG
2020-04-22 19:07:51 +05:30
If you want to create a changelog entry for GitLab FOSS , run the following :
2018-11-18 11:00:15 +05:30
` ` `
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 "
` ` `
2020-05-24 23:13:21 +05:30
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-11-18 11:00:15 +05:30
MSG
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
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?
2020-01-12 00:16:45 +05:30
if yaml [ " merge_request " ] . nil? && ! helper . security_mr?
2020-06-23 00:09:42 +05:30
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-04-22 19:07:51 +05:30
elsif yaml [ " merge_request " ] != gitlab . mr_json [ " iid " ] && ! helper . security_mr?
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
2020-04-22 19:07:51 +05:30
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-03-13 15:44:24 +05:30
def sanitized_mr_title
helper . sanitize_mr_title ( gitlab . mr_json [ " title " ] )
end
2018-11-18 11:00:15 +05:30
if git . modified_files . include? ( " CHANGELOG.md " )
fail " **CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry. \n \n " +
2020-05-24 23:13:21 +05:30
format ( CREATE_CHANGELOG_MESSAGE , mr_iid : gitlab . mr_json [ " iid " ] , mr_title : sanitized_mr_title )
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 )
elsif changelog . needed?
2020-05-24 23:13:21 +05:30
message " **[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html)**: \n \n " +
format ( CREATE_CHANGELOG_MESSAGE , mr_iid : gitlab . mr_json [ " iid " ] , mr_title : sanitized_mr_title )
2018-11-18 11:00:15 +05:30
end