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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
641b058b
Commit
641b058b
authored
Mar 05, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MR merge commit cross-references to the MR itself
parent
cb9148fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
34 deletions
+47
-34
app/workers/process_commit_worker.rb
app/workers/process_commit_worker.rb
+3
-4
spec/workers/process_commit_worker_spec.rb
spec/workers/process_commit_worker_spec.rb
+44
-30
No files found.
app/workers/process_commit_worker.rb
View file @
641b058b
...
@@ -30,10 +30,9 @@ class ProcessCommitWorker
...
@@ -30,10 +30,9 @@ class ProcessCommitWorker
end
end
def
process_commit_message
(
project
,
commit
,
user
,
author
,
default
=
false
)
def
process_commit_message
(
project
,
commit
,
user
,
author
,
default
=
false
)
# this is a GitLab generated commit message, ignore it.
# Ignore closing references from GitLab-generated commit messages.
return
if
commit
.
merged_merge_request?
(
user
)
find_closing_issues
=
default
&&
!
commit
.
merged_merge_request?
(
user
)
closed_issues
=
find_closing_issues
?
commit
.
closes_issues
(
user
)
:
[]
closed_issues
=
default
?
commit
.
closes_issues
(
user
)
:
[]
close_issues
(
project
,
user
,
author
,
commit
,
closed_issues
)
if
closed_issues
.
any?
close_issues
(
project
,
user
,
author
,
commit
,
closed_issues
)
if
closed_issues
.
any?
commit
.
create_cross_references!
(
author
,
closed_issues
)
commit
.
create_cross_references!
(
author
,
closed_issues
)
...
...
spec/workers/process_commit_worker_spec.rb
View file @
641b058b
...
@@ -20,32 +20,6 @@ describe ProcessCommitWorker do
...
@@ -20,32 +20,6 @@ describe ProcessCommitWorker do
worker
.
perform
(
project
.
id
,
-
1
,
commit
.
to_hash
)
worker
.
perform
(
project
.
id
,
-
1
,
commit
.
to_hash
)
end
end
context
'when commit is a merge request merge commit'
do
let
(
:merge_request
)
do
create
(
:merge_request
,
description:
"Closes
#{
issue
.
to_reference
}
"
,
source_branch:
'feature-merged'
,
target_branch:
'master'
,
source_project:
project
)
end
let
(
:commit
)
do
project
.
repository
.
create_branch
(
'feature-merged'
,
'feature'
)
sha
=
project
.
repository
.
merge
(
user
,
merge_request
.
diff_head_sha
,
merge_request
,
"Closes
#{
issue
.
to_reference
}
"
)
project
.
repository
.
commit
(
sha
)
end
it
'it does not close any issues from the commit message'
do
expect
(
worker
).
not_to
receive
(
:close_issues
)
worker
.
perform
(
project
.
id
,
user
.
id
,
commit
.
to_hash
)
end
end
it
'processes the commit message'
do
it
'processes the commit message'
do
expect
(
worker
).
to
receive
(
:process_commit_message
).
and_call_original
expect
(
worker
).
to
receive
(
:process_commit_message
).
and_call_original
...
@@ -73,13 +47,21 @@ describe ProcessCommitWorker do
...
@@ -73,13 +47,21 @@ describe ProcessCommitWorker do
describe
'#process_commit_message'
do
describe
'#process_commit_message'
do
context
'when pushing to the default branch'
do
context
'when pushing to the default branch'
do
it
'closes issues that should be closed per the commit message'
do
before
do
allow
(
commit
).
to
receive
(
:safe_message
).
and_return
(
"Closes
#{
issue
.
to_reference
}
"
)
allow
(
commit
).
to
receive
(
:safe_message
).
and_return
(
"Closes
#{
issue
.
to_reference
}
"
)
end
it
'closes issues that should be closed per the commit message'
do
expect
(
worker
).
to
receive
(
:close_issues
).
with
(
project
,
user
,
user
,
commit
,
[
issue
])
expect
(
worker
).
to
receive
(
:close_issues
).
with
(
project
,
user
,
user
,
commit
,
[
issue
])
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
true
)
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
true
)
end
end
it
'creates cross references'
do
expect
(
commit
).
to
receive
(
:create_cross_references!
).
with
(
user
,
[
issue
])
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
true
)
end
end
end
context
'when pushing to a non-default branch'
do
context
'when pushing to a non-default branch'
do
...
@@ -90,12 +72,44 @@ describe ProcessCommitWorker do
...
@@ -90,12 +72,44 @@ describe ProcessCommitWorker do
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
false
)
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
false
)
end
end
it
'does not create cross references'
do
expect
(
commit
).
to
receive
(
:create_cross_references!
).
with
(
user
,
[])
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
false
)
end
end
end
it
'creates cross references'
do
context
'when commit is a merge request merge commit to the default branch'
do
expect
(
commit
).
to
receive
(
:create_cross_references!
)
let
(
:merge_request
)
do
create
(
:merge_request
,
description:
"Closes
#{
issue
.
to_reference
}
"
,
source_branch:
'feature-merged'
,
target_branch:
'master'
,
source_project:
project
)
end
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
)
let
(
:commit
)
do
project
.
repository
.
create_branch
(
'feature-merged'
,
'feature'
)
MergeRequests
::
MergeService
.
new
(
project
,
merge_request
.
author
)
.
execute
(
merge_request
)
merge_request
.
reload
.
merge_commit
end
it
'does not close any issues from the commit message'
do
expect
(
worker
).
not_to
receive
(
:close_issues
)
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
true
)
end
it
'still creates cross references'
do
expect
(
commit
).
to
receive
(
:create_cross_references!
).
with
(
user
,
[])
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
true
)
end
end
end
end
end
...
...
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