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
bin/changelog --ee -m %<mr_iid>s "%<mr_title>s"
```
Note: Merge requests with %<labels>s do not trigger this check.
MSG
def check_changelog_yaml(path)
......@@ -57,7 +56,7 @@ end
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: changelog.presented_no_changelog_labels)
format(CREATE_CHANGELOG_MESSAGE, mr_iid: gitlab.mr_json["iid"], mr_title: sanitized_mr_title)
end
changelog_found = changelog.found
......@@ -67,5 +66,5 @@ if changelog_found
check_changelog_path(changelog_found)
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" +
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
......@@ -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.
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_spec_changes = !helper.all_changed_files.grep(%r{\A(ee/)?spec/}).empty?
new_specs_needed = (gitlab.mr_labels & NO_SPECS_LABELS).empty?
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
......@@ -14,10 +14,6 @@ module Gitlab
@found ||= git.added_files.find { |path| path =~ %r{\A(ee/)?(changelogs/unreleased)(-ee)?/} }
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
......
......@@ -198,11 +198,14 @@ module Gitlab
(labels & gitlab_helper.mr_labels) == labels
end
def labels_list(labels, sep: ', ')
labels.map { |label| %Q{~"#{label}"} }.join(sep)
end
def prepare_labels_for_mr(labels)
return '' unless labels.any?
labels_list = labels.map { |label| %Q{~"#{label}"} }.join(' ')
"/label #{labels_list}"
"/label #{labels_list(labels, sep: ' ')}"
end
private
......
......@@ -86,14 +86,6 @@ describe Gitlab::Danger::Changelog do
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
subject { changelog.ee_changelog? }
......
......@@ -399,9 +399,28 @@ describe Gitlab::Danger::Helper do
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
it 'composes the labels string' do
mr_labels = ['telemetry', 'telemetry::reviewed']
expect(helper.prepare_labels_for_mr(mr_labels)).to eq('/label ~"telemetry" ~"telemetry::reviewed"')
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