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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
7c288c07
Commit
7c288c07
authored
Feb 22, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check the HEAD of branch when doing Merge When Succeeded
parent
04d1b412
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
app/services/merge_requests/merge_when_build_succeeds_service.rb
...vices/merge_requests/merge_when_build_succeeds_service.rb
+9
-3
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
.../merge_requests/merge_when_build_succeeds_service_spec.rb
+16
-0
No files found.
app/services/merge_requests/merge_when_build_succeeds_service.rb
View file @
7c288c07
...
...
@@ -24,12 +24,16 @@ module MergeRequests
merge_requests
.
each
do
|
merge_request
|
next
unless
merge_request
.
merge_when_build_succeeds?
next
unless
merge_request
.
mergeable?
ci_commit
=
merge_request
.
ci_commit
next
unless
ci_commit
next
unless
ci_commit
.
sha
==
commit_status
.
sha
next
unless
ci_commit
.
success?
if
merge_request
.
ci_commit
&&
merge_request
.
ci_commit
.
success?
&&
merge_request
.
mergeable?
MergeWorker
.
perform_async
(
merge_request
.
id
,
merge_request
.
merge_user_id
,
merge_request
.
merge_params
)
end
end
end
# Cancels the automatic merge
def
cancel
(
merge_request
)
...
...
@@ -51,6 +55,8 @@ module MergeRequests
# This is for ref-less builds
branches
||=
@project
.
repository
.
branch_names_contains
(
commit_status
.
sha
)
return
[]
if
branches
.
blank?
merge_requests
=
@project
.
origin_merge_requests
.
opened
.
where
(
source_branch:
branches
).
to_a
merge_requests
+=
@project
.
fork_merge_requests
.
opened
.
where
(
source_branch:
branches
).
to_a
...
...
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
View file @
7c288c07
...
...
@@ -66,9 +66,25 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
end
end
context
'triggered by an old build'
do
let
(
:old_build
)
{
create
(
:ci_build
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
status:
"success"
)
}
let
(
:build
)
{
create
(
:ci_build
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
status:
"success"
)
}
it
"merges all merge requests with merge when build succeeds enabled"
do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:ci_commit
).
and_return
(
ci_commit
)
allow
(
ci_commit
).
to
receive
(
:success?
).
and_return
(
true
)
allow
(
old_build
).
to
receive
(
:sha
).
and_return
(
'1234abcdef'
)
expect
(
MergeWorker
).
to_not
receive
(
:perform_async
)
service
.
trigger
(
old_build
)
end
end
context
'commit status without ref'
do
let
(
:commit_status
)
{
create
(
:generic_commit_status
,
status:
'success'
)
}
before
{
mr_merge_if_green_enabled
}
it
"doesn't merge a requests for status on other branch"
do
allow
(
project
.
repository
).
to
receive
(
:branch_names_contains
).
with
(
commit_status
.
sha
).
and_return
([])
...
...
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