2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2021-03-08 18:12:59 +05:30
require_relative 'title_linting'
2021-03-11 19:13:27 +05:30
module Tooling
2020-01-01 13:55:28 +05:30
module Danger
module Changelog
2020-07-28 23:09:34 +05:30
NO_CHANGELOG_LABELS = [
'tooling' ,
'tooling::pipelines' ,
'tooling::workflow' ,
'ci-build' ,
'meta'
] . freeze
2020-01-01 13:55:28 +05:30
NO_CHANGELOG_CATEGORIES = % i [ docs none ] . freeze
2020-11-24 15:15:51 +05:30
CREATE_CHANGELOG_COMMAND = 'bin/changelog -m %<mr_iid>s "%<mr_title>s"'
CREATE_EE_CHANGELOG_COMMAND = 'bin/changelog --ee -m %<mr_iid>s "%<mr_title>s"'
CHANGELOG_MODIFIED_URL_TEXT = " **CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry. \n \n "
CHANGELOG_MISSING_URL_TEXT = " **[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html)**: \n \n "
2020-01-01 13:55:28 +05:30
2020-11-24 15:15:51 +05:30
OPTIONAL_CHANGELOG_MESSAGE = << ~ MSG
If you want to create a changelog entry for GitLab FOSS , run the following :
#{CREATE_CHANGELOG_COMMAND}
If you want to create a changelog entry for GitLab EE , run the following instead :
#{CREATE_EE_CHANGELOG_COMMAND}
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.
MSG
REQUIRED_CHANGELOG_MESSAGE = << ~ MSG
To create a changelog entry , run the following :
#{CREATE_CHANGELOG_COMMAND}
This merge request requires a changelog entry because it [ introduces a database migration ] ( https : / / docs . gitlab . com / ee / development / changelog . html #what-warrants-a-changelog-entry).
MSG
def required?
git . added_files . any? { | path | path =~ %r{ \ Adb/(migrate|post_migrate)/ } }
end
2021-02-22 17:27:13 +05:30
alias_method :db_changes? , :required?
2020-11-24 15:15:51 +05:30
def optional?
2020-07-28 23:09:34 +05:30
categories_need_changelog? && without_no_changelog_label?
2020-01-01 13:55:28 +05:30
end
def found
2020-04-22 19:07:51 +05:30
@found || = git . added_files . find { | path | path =~ %r{ \ A(ee/)?(changelogs/unreleased)(-ee)?/ } }
2020-01-01 13:55:28 +05:30
end
2020-04-22 19:07:51 +05:30
def ee_changelog?
found . start_with? ( 'ee/' )
2020-01-01 13:55:28 +05:30
end
2020-11-24 15:15:51 +05:30
def modified_text
CHANGELOG_MODIFIED_URL_TEXT +
format ( OPTIONAL_CHANGELOG_MESSAGE , mr_iid : mr_iid , mr_title : sanitized_mr_title )
end
def required_text
CHANGELOG_MISSING_URL_TEXT +
format ( REQUIRED_CHANGELOG_MESSAGE , mr_iid : mr_iid , mr_title : sanitized_mr_title )
end
def optional_text
CHANGELOG_MISSING_URL_TEXT +
format ( OPTIONAL_CHANGELOG_MESSAGE , mr_iid : mr_iid , mr_title : sanitized_mr_title )
end
2020-01-01 13:55:28 +05:30
private
2020-11-24 15:15:51 +05:30
def mr_iid
gitlab . mr_json [ " iid " ]
end
def sanitized_mr_title
2021-03-08 18:12:59 +05:30
TitleLinting . sanitize_mr_title ( gitlab . mr_json [ " title " ] )
2020-11-24 15:15:51 +05:30
end
2020-01-01 13:55:28 +05:30
def categories_need_changelog?
( helper . changes_by_category . keys - NO_CHANGELOG_CATEGORIES ) . any?
end
2020-07-28 23:09:34 +05:30
def without_no_changelog_label?
( gitlab . mr_labels & NO_CHANGELOG_LABELS ) . empty?
end
2020-01-01 13:55:28 +05:30
end
end
end