Commit a600a498 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'dont-advertise-labels-that-disable-changelog' into 'master'

Don't advertise the labels that disable changelog requirement

See merge request gitlab-org/gitlab!30514
parents de4160af 5a58db31
...@@ -17,7 +17,6 @@ If you want to create a changelog entry for GitLab EE, run the following instead ...@@ -17,7 +17,6 @@ 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" bin/changelog --ee -m %<mr_iid>s "%<mr_title>s"
``` ```
Note: Merge requests with %<labels>s do not trigger this check.
MSG MSG
def check_changelog_yaml(path) def check_changelog_yaml(path)
...@@ -57,7 +56,7 @@ end ...@@ -57,7 +56,7 @@ end
if git.modified_files.include?("CHANGELOG.md") if git.modified_files.include?("CHANGELOG.md")
fail "**CHANGELOG.md was edited.** Please remove the additions and create a CHANGELOG entry.\n\n" + 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: changelog.presented_no_changelog_labels) format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: sanitized_mr_title)
end end
changelog_found = changelog.found changelog_found = changelog.found
...@@ -67,5 +66,5 @@ if changelog_found ...@@ -67,5 +66,5 @@ if changelog_found
check_changelog_path(changelog_found) check_changelog_path(changelog_found)
elsif changelog.needed? elsif changelog.needed?
message "**[CHANGELOG missing](https://docs.gitlab.com/ee/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" + message "**[CHANGELOG missing](https://docs.gitlab.com/ee/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: changelog.presented_no_changelog_labels) format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: sanitized_mr_title)
end end
...@@ -7,14 +7,10 @@ That's OK as long as you're refactoring existing code, ...@@ -7,14 +7,10 @@ That's OK as long as you're refactoring existing code,
but please consider adding any of the %<labels>s labels. but please consider adding any of the %<labels>s labels.
MSG MSG
def presented_no_changelog_labels
NO_SPECS_LABELS.map { |label| "~#{label}" }.join(', ')
end
has_app_changes = !helper.all_changed_files.grep(%r{\A(ee/)?(app|lib|db/(geo/)?(post_)?migrate)/}).empty? has_app_changes = !helper.all_changed_files.grep(%r{\A(ee/)?(app|lib|db/(geo/)?(post_)?migrate)/}).empty?
has_spec_changes = !helper.all_changed_files.grep(%r{\A(ee/)?spec/}).empty? has_spec_changes = !helper.all_changed_files.grep(%r{\A(ee/)?spec/}).empty?
new_specs_needed = (gitlab.mr_labels & NO_SPECS_LABELS).empty? new_specs_needed = (gitlab.mr_labels & NO_SPECS_LABELS).empty?
if has_app_changes && !has_spec_changes && new_specs_needed if has_app_changes && !has_spec_changes && new_specs_needed
warn format(NO_NEW_SPEC_MESSAGE, labels: presented_no_changelog_labels), sticky: false warn format(NO_NEW_SPEC_MESSAGE, labels: helper.labels_list(NO_SPECS_LABELS)), sticky: false
end end
...@@ -14,10 +14,6 @@ module Gitlab ...@@ -14,10 +14,6 @@ module Gitlab
@found ||= git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} } @found ||= git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} }
end end
def presented_no_changelog_labels
NO_CHANGELOG_LABELS.map { |label| "~#{label}" }.join(', ')
end
def sanitized_mr_title def sanitized_mr_title
gitlab.mr_json["title"].gsub(/^WIP: */, '').gsub(/`/, '\\\`') gitlab.mr_json["title"].gsub(/^WIP: */, '').gsub(/`/, '\\\`')
end end
......
...@@ -198,11 +198,14 @@ module Gitlab ...@@ -198,11 +198,14 @@ module Gitlab
(labels & gitlab_helper.mr_labels) == labels (labels & gitlab_helper.mr_labels) == labels
end end
def labels_list(labels, sep: ', ')
labels.map { |label| %Q{~"#{label}"} }.join(sep)
end
def prepare_labels_for_mr(labels) def prepare_labels_for_mr(labels)
return '' unless labels.any? return '' unless labels.any?
labels_list = labels.map { |label| %Q{~"#{label}"} }.join(' ') "/label #{labels_list(labels, sep: ' ')}"
"/label #{labels_list}"
end end
private private
......
...@@ -86,14 +86,6 @@ describe Gitlab::Danger::Changelog do ...@@ -86,14 +86,6 @@ describe Gitlab::Danger::Changelog do
end end
end end
describe '#presented_no_changelog_labels' do
subject { changelog.presented_no_changelog_labels }
it 'returns the labels formatted' do
is_expected.to eq('~backstage, ~ci-build, ~meta')
end
end
describe '#ee_changelog?' do describe '#ee_changelog?' do
subject { changelog.ee_changelog? } subject { changelog.ee_changelog? }
......
...@@ -399,9 +399,28 @@ describe Gitlab::Danger::Helper do ...@@ -399,9 +399,28 @@ describe Gitlab::Danger::Helper do
end end
end end
describe '#labels_list' do
let(:labels) { ['telemetry', 'telemetry::reviewed'] }
it 'composes the labels string' do
expect(helper.labels_list(labels)).to eq('~"telemetry", ~"telemetry::reviewed"')
end
context 'when passing a separator' do
it 'composes the labels string with the given separator' do
expect(helper.labels_list(labels, sep: ' ')).to eq('~"telemetry" ~"telemetry::reviewed"')
end
end
it 'returns empty string for empty array' do
expect(helper.labels_list([])).to eq('')
end
end
describe '#prepare_labels_for_mr' do describe '#prepare_labels_for_mr' do
it 'composes the labels string' do it 'composes the labels string' do
mr_labels = ['telemetry', 'telemetry::reviewed'] mr_labels = ['telemetry', 'telemetry::reviewed']
expect(helper.prepare_labels_for_mr(mr_labels)).to eq('/label ~"telemetry" ~"telemetry::reviewed"') expect(helper.prepare_labels_for_mr(mr_labels)).to eq('/label ~"telemetry" ~"telemetry::reviewed"')
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment