Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9253e349
Commit
9253e349
authored
Jun 24, 2020
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't error on wrong MR IID in changelog for cherry-pick MRs
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
089b43a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
2 deletions
+81
-2
danger/changelog/Dangerfile
danger/changelog/Dangerfile
+6
-2
lib/gitlab/danger/helper.rb
lib/gitlab/danger/helper.rb
+12
-0
spec/lib/gitlab/danger/helper_spec.rb
spec/lib/gitlab/danger/helper_spec.rb
+63
-0
No files found.
danger/changelog/Dangerfile
View file @
9253e349
...
...
@@ -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
"`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
"
)
if
mr_line
...
...
@@ -43,7 +47,7 @@ def check_changelog_yaml(path)
else
message
"Consider setting `merge_request` to
#{
gitlab
.
mr_json
[
"iid"
]
}
in
#{
gitlab
.
html_link
(
path
)
}
.
#{
SEE_DOC
}
"
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
}
"
end
rescue
Psych
::
SyntaxError
,
Psych
::
DisallowedClass
,
Psych
::
BadAlias
...
...
lib/gitlab/danger/helper.rb
View file @
9253e349
...
...
@@ -193,6 +193,18 @@ module Gitlab
gitlab_helper
.
mr_json
[
'web_url'
].
include?
(
'/gitlab-org/security/'
)
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
)
return
false
unless
gitlab_helper
...
...
spec/lib/gitlab/danger/helper_spec.rb
View file @
9253e349
...
...
@@ -366,6 +366,69 @@ RSpec.describe Gitlab::Danger::Helper do
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
it
'returns false when `gitlab_helper` is unavailable'
do
expect
(
helper
).
to
receive
(
:gitlab_helper
).
and_return
(
nil
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment