Commit 6ccb24f1 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'dont-error-on-wrong-mr-iid-in-changelog-for-cherry-pick-mr' into 'master'

Don't error on wrong MR IID in changelog for cherry pick MRs

See merge request gitlab-org/gitlab!35252
parents 70bf01c4 9253e349
...@@ -35,7 +35,11 @@ def check_changelog_yaml(path) ...@@ -35,7 +35,11 @@ def check_changelog_yaml(path)
fail "`title` should be set, in #{gitlab.html_link(path)}! #{SEE_DOC}" if yaml["title"].nil? fail "`title` should be set, in #{gitlab.html_link(path)}! #{SEE_DOC}" if yaml["title"].nil?
fail "`type` should be set, in #{gitlab.html_link(path)}! #{SEE_DOC}" if yaml["type"].nil? fail "`type` should be set, in #{gitlab.html_link(path)}! #{SEE_DOC}" if yaml["type"].nil?
if yaml["merge_request"].nil? && !helper.security_mr? return if helper.security_mr?
cherry_pick_against_stable_branch = helper.cherry_pick_mr? && helper.stable_branch?
if yaml["merge_request"].nil?
mr_line = raw_file.lines.find_index("merge_request:\n") mr_line = raw_file.lines.find_index("merge_request:\n")
if mr_line if mr_line
...@@ -43,7 +47,7 @@ def check_changelog_yaml(path) ...@@ -43,7 +47,7 @@ def check_changelog_yaml(path)
else else
message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{gitlab.html_link(path)}. #{SEE_DOC}" message "Consider setting `merge_request` to #{gitlab.mr_json["iid"]} in #{gitlab.html_link(path)}. #{SEE_DOC}"
end end
elsif yaml["merge_request"] != gitlab.mr_json["iid"] && !helper.security_mr? elsif yaml["merge_request"] != gitlab.mr_json["iid"] && !cherry_pick_against_stable_branch
fail "Merge request ID was not set to #{gitlab.mr_json["iid"]}! #{SEE_DOC}" fail "Merge request ID was not set to #{gitlab.mr_json["iid"]}! #{SEE_DOC}"
end end
rescue Psych::SyntaxError, Psych::DisallowedClass, Psych::BadAlias rescue Psych::SyntaxError, Psych::DisallowedClass, Psych::BadAlias
......
...@@ -196,6 +196,18 @@ module Gitlab ...@@ -196,6 +196,18 @@ module Gitlab
gitlab_helper.mr_json['web_url'].include?('/gitlab-org/security/') gitlab_helper.mr_json['web_url'].include?('/gitlab-org/security/')
end end
def cherry_pick_mr?
return false unless gitlab_helper
/cherry[\s-]*pick/i.match?(gitlab_helper.mr_json['title'])
end
def stable_branch?
return false unless gitlab_helper
/\A\d+-\d+-stable-ee/i.match?(gitlab_helper.mr_json['target_branch'])
end
def mr_has_labels?(*labels) def mr_has_labels?(*labels)
return false unless gitlab_helper return false unless gitlab_helper
......
...@@ -369,6 +369,69 @@ RSpec.describe Gitlab::Danger::Helper do ...@@ -369,6 +369,69 @@ RSpec.describe Gitlab::Danger::Helper do
end end
end end
describe '#cherry_pick_mr?' do
it 'returns false when `gitlab_helper` is unavailable' do
expect(helper).to receive(:gitlab_helper).and_return(nil)
expect(helper).not_to be_cherry_pick_mr
end
context 'when MR title does not mention a cherry-pick' do
it 'returns false' do
expect(fake_gitlab).to receive(:mr_json)
.and_return('title' => 'Add feature xyz')
expect(helper).not_to be_cherry_pick_mr
end
end
context 'when MR title mentions a cherry-pick' do
[
'Cherry Pick !1234',
'cherry-pick !1234',
'CherryPick !1234'
].each do |mr_title|
it 'returns true' do
expect(fake_gitlab).to receive(:mr_json)
.and_return('title' => mr_title)
expect(helper).to be_cherry_pick_mr
end
end
end
end
describe '#stable_branch?' do
it 'returns false when `gitlab_helper` is unavailable' do
expect(helper).to receive(:gitlab_helper).and_return(nil)
expect(helper).not_to be_stable_branch
end
context 'when MR target branch is not a stable branch' do
it 'returns false' do
expect(fake_gitlab).to receive(:mr_json)
.and_return('target_branch' => 'my-feature-branch')
expect(helper).not_to be_stable_branch
end
end
context 'when MR target branch is a stable branch' do
%w[
13-1-stable-ee
13-1-stable-ee-patch-1
].each do |target_branch|
it 'returns true' do
expect(fake_gitlab).to receive(:mr_json)
.and_return('target_branch' => target_branch)
expect(helper).to be_stable_branch
end
end
end
end
describe '#mr_has_label?' do describe '#mr_has_label?' do
it 'returns false when `gitlab_helper` is unavailable' do it 'returns false when `gitlab_helper` is unavailable' do
expect(helper).to receive(:gitlab_helper).and_return(nil) expect(helper).to receive(:gitlab_helper).and_return(nil)
......
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