summaryrefslogtreecommitdiff
path: root/tooling/danger/changelog.rb
diff options
context:
space:
mode:
Diffstat (limited to 'tooling/danger/changelog.rb')
-rw-r--r--tooling/danger/changelog.rb43
1 files changed, 26 insertions, 17 deletions
diff --git a/tooling/danger/changelog.rb b/tooling/danger/changelog.rb
index f7f505f51a6..672d23d58e4 100644
--- a/tooling/danger/changelog.rb
+++ b/tooling/danger/changelog.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require_relative 'title_linting'
+require 'gitlab/dangerfiles/title_linting'
module Tooling
module Danger
@@ -30,25 +30,35 @@ module Tooling
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_REASONS = {
+ db_changes: 'introduces a database migration',
+ feature_flag_removed: 'removes a feature flag'
+ }.freeze
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).
+ This merge request requires a changelog entry because it [%<reason>s](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry).
MSG
+ def required_reasons
+ [].tap do |reasons|
+ reasons << :db_changes if project_helper.changes.added.has_category?(:migration)
+ reasons << :feature_flag_removed if project_helper.changes.deleted.has_category?(:feature_flag)
+ end
+ end
+
def required?
- git.added_files.any? { |path| path =~ %r{\Adb/(migrate|post_migrate)/} }
+ required_reasons.any?
end
- alias_method :db_changes?, :required?
def optional?
categories_need_changelog? && without_no_changelog_label?
end
def found
- @found ||= git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} }
+ @found ||= project_helper.changes.added.by_category(:changelog).files.first
end
def ee_changelog?
@@ -57,35 +67,34 @@ module Tooling
def modified_text
CHANGELOG_MODIFIED_URL_TEXT +
- format(OPTIONAL_CHANGELOG_MESSAGE, mr_iid: mr_iid, mr_title: sanitized_mr_title)
+ format(OPTIONAL_CHANGELOG_MESSAGE, mr_iid: helper.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)
+ def required_texts
+ required_reasons.each_with_object({}) do |required_reason, memo|
+ memo[required_reason] =
+ CHANGELOG_MISSING_URL_TEXT +
+ format(REQUIRED_CHANGELOG_MESSAGE, reason: REQUIRED_CHANGELOG_REASONS.fetch(required_reason), mr_iid: helper.mr_iid, mr_title: sanitized_mr_title)
+ end
end
def optional_text
CHANGELOG_MISSING_URL_TEXT +
- format(OPTIONAL_CHANGELOG_MESSAGE, mr_iid: mr_iid, mr_title: sanitized_mr_title)
+ format(OPTIONAL_CHANGELOG_MESSAGE, mr_iid: helper.mr_iid, mr_title: sanitized_mr_title)
end
private
- def mr_iid
- gitlab.mr_json["iid"]
- end
-
def sanitized_mr_title
- TitleLinting.sanitize_mr_title(gitlab.mr_json["title"])
+ Gitlab::Dangerfiles::TitleLinting.sanitize_mr_title(helper.mr_title)
end
def categories_need_changelog?
- (helper.changes_by_category.keys - NO_CHANGELOG_CATEGORIES).any?
+ (project_helper.changes.categories - NO_CHANGELOG_CATEGORIES).any?
end
def without_no_changelog_label?
- (gitlab.mr_labels & NO_CHANGELOG_LABELS).empty?
+ (helper.mr_labels & NO_CHANGELOG_LABELS).empty?
end
end
end