summaryrefslogtreecommitdiff
path: root/danger
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-12 15:08:41 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-12 15:08:41 +0000
commit27859ed5eaeae234162b7cce7fd8bd351b5f9369 (patch)
tree5a62db348c3fd73516df87262c78e3546d4ec770 /danger
parent784fae4b9d7e92350075df2a43d06893080ed1e6 (diff)
downloadgitlab-ce-27859ed5eaeae234162b7cce7fd8bd351b5f9369.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'danger')
-rw-r--r--danger/changelog/Dangerfile34
-rw-r--r--danger/plugins/changelog.rb10
2 files changed, 16 insertions, 28 deletions
diff --git a/danger/changelog/Dangerfile b/danger/changelog/Dangerfile
index f8e31323f41..62b41d14bee 100644
--- a/danger/changelog/Dangerfile
+++ b/danger/changelog/Dangerfile
@@ -3,7 +3,6 @@
require 'yaml'
-NO_CHANGELOG_LABELS = %w[backstage ci-build meta].freeze
SEE_DOC = "See [the documentation](https://docs.gitlab.com/ce/development/changelog.html)."
CREATE_CHANGELOG_MESSAGE = <<~MSG
You can create one with:
@@ -21,18 +20,6 @@ bin/changelog --ee -m %<mr_iid>s "%<mr_title>s"
Note: Merge requests with %<labels>s do not trigger this check.
MSG
-def ee_changelog?(changelog_path)
- changelog_path =~ /unreleased-ee/
-end
-
-def ce_port_changelog?(changelog_path)
- helper.ee? && !ee_changelog?(changelog_path)
-end
-
-def categories_need_changelog?
- (helper.changes_by_category.keys - %i[docs none]).any?
-end
-
def check_changelog(path)
yaml = YAML.safe_load(File.read(path))
@@ -41,7 +28,7 @@ def check_changelog(path)
if yaml["merge_request"].nil?
message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{gitlab.html_link(path)}. #{SEE_DOC}"
- elsif yaml["merge_request"] != gitlab.mr_json["iid"] && !ce_port_changelog?(path)
+ elsif yaml["merge_request"] != gitlab.mr_json["iid"] && !changelog.ce_port_changelog?(path)
fail "Merge request ID was not set to #{gitlab.mr_json["iid"]}! #{SEE_DOC}"
end
rescue Psych::SyntaxError, Psych::DisallowedClass, Psych::BadAlias
@@ -51,27 +38,18 @@ rescue StandardError => e
warn "There was a problem trying to check the Changelog. Exception: #{e.name} - #{e.message}"
end
-def presented_no_changelog_labels
- NO_CHANGELOG_LABELS.map { |label| "~#{label}" }.join(', ')
-end
-
-def sanitized_mr_title
- gitlab.mr_json["title"].gsub(/^WIP: */, '').gsub(/`/, '\\\`')
-end
-
-changelog_needed = categories_need_changelog? && (gitlab.mr_labels & NO_CHANGELOG_LABELS).empty?
-changelog_found = git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} }
-
if git.modified_files.include?("CHANGELOG.md")
fail "**CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry.\n\n" +
- format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: sanitized_mr_title, labels: presented_no_changelog_labels)
+ format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: changelog.sanitized_mr_title, labels: changelog.presented_no_changelog_labels)
end
-if changelog_needed
+changelog_found = changelog.found
+
+if changelog.needed?
if changelog_found
check_changelog(changelog_found)
else
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" +
- format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: sanitized_mr_title, labels: presented_no_changelog_labels)
+ format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: changelog.sanitized_mr_title, labels: changelog.presented_no_changelog_labels)
end
end
diff --git a/danger/plugins/changelog.rb b/danger/plugins/changelog.rb
new file mode 100644
index 00000000000..84f399e9e97
--- /dev/null
+++ b/danger/plugins/changelog.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+require_relative '../../lib/gitlab/danger/changelog'
+
+module Danger
+ class Changelog < Plugin
+ # Put the helper code somewhere it can be tested
+ include Gitlab::Danger::Changelog
+ end
+end