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
Léo-Paul Géneau
gitlab-ce
Commits
6febe100
Commit
6febe100
authored
Feb 19, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Discover branches for commit statuses ref-less when doing merge when succeeded
parent
56449cc6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
11 deletions
+41
-11
CHANGELOG
CHANGELOG
+1
-0
app/services/merge_requests/merge_when_build_succeeds_service.rb
...vices/merge_requests/merge_when_build_succeeds_service.rb
+10
-5
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
.../merge_requests/merge_when_build_succeeds_service_spec.rb
+30
-6
No files found.
CHANGELOG
View file @
6febe100
...
@@ -46,6 +46,7 @@ v 8.5.0 (unreleased)
...
@@ -46,6 +46,7 @@ v 8.5.0 (unreleased)
- Deprecate API "merge_request/:merge_request_id/comments". Use "merge_requests/:merge_request_id/notes" instead
- Deprecate API "merge_request/:merge_request_id/comments". Use "merge_requests/:merge_request_id/notes" instead
- Deprecate API "merge_request/:merge_request_id/...". Use "merge_requests/:merge_request_id/..." instead
- Deprecate API "merge_request/:merge_request_id/...". Use "merge_requests/:merge_request_id/..." instead
- Prevent parse error when name of project ends with .atom and prevent path issues
- Prevent parse error when name of project ends with .atom and prevent path issues
- Discover branches for commit statuses ref-less when doing merge when succeeded
- Mark inline difference between old and new paths when a file is renamed
- Mark inline difference between old and new paths when a file is renamed
- Support Akismet spam checking for creation of issues via API (Stan Hu)
- Support Akismet spam checking for creation of issues via API (Stan Hu)
- API: Allow to set or update a merge-request's milestone (Kirill Skachkov)
- API: Allow to set or update a merge-request's milestone (Kirill Skachkov)
...
...
app/services/merge_requests/merge_when_build_succeeds_service.rb
View file @
6febe100
...
@@ -19,8 +19,8 @@ module MergeRequests
...
@@ -19,8 +19,8 @@ module MergeRequests
end
end
# Triggers the automatic merge of merge_request once the build succeeds
# Triggers the automatic merge of merge_request once the build succeeds
def
trigger
(
build
)
def
trigger
(
commit_status
)
merge_requests
=
merge_request_from
(
build
)
merge_requests
=
merge_request_from
(
commit_status
)
merge_requests
.
each
do
|
merge_request
|
merge_requests
.
each
do
|
merge_request
|
next
unless
merge_request
.
merge_when_build_succeeds?
next
unless
merge_request
.
merge_when_build_succeeds?
...
@@ -45,9 +45,14 @@ module MergeRequests
...
@@ -45,9 +45,14 @@ module MergeRequests
private
private
def
merge_request_from
(
build
)
def
merge_request_from
(
commit_status
)
merge_requests
=
@project
.
origin_merge_requests
.
opened
.
where
(
source_branch:
build
.
ref
).
to_a
branches
=
commit_status
.
ref
merge_requests
+=
@project
.
fork_merge_requests
.
opened
.
where
(
source_branch:
build
.
ref
).
to_a
# This is for ref-less builds
branches
||=
@project
.
repository
.
branch_names_contains
(
commit_status
.
sha
)
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
merge_requests
.
uniq
.
select
(
&
:source_project
)
merge_requests
.
uniq
.
select
(
&
:source_project
)
end
end
...
...
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
View file @
6febe100
...
@@ -54,6 +54,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
...
@@ -54,6 +54,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
end
end
describe
"#trigger"
do
describe
"#trigger"
do
context
'build with ref'
do
let
(
: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
it
"merges all merge requests with merge when build succeeds enabled"
do
...
@@ -63,6 +64,29 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
...
@@ -63,6 +64,29 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
expect
(
MergeWorker
).
to
receive
(
:perform_async
)
expect
(
MergeWorker
).
to
receive
(
:perform_async
)
service
.
trigger
(
build
)
service
.
trigger
(
build
)
end
end
end
context
'commit status without ref'
do
let
(
:commit_status
)
{
create
(
:generic_commit_status
,
status:
'success'
)
}
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
([])
expect
(
MergeWorker
).
to_not
receive
(
:perform_async
)
service
.
trigger
(
commit_status
)
end
it
'discovers branches and merges all merge requests when status is success'
do
allow
(
project
.
repository
).
to
receive
(
:branch_names_contains
).
with
(
commit_status
.
sha
).
and_return
([
mr_merge_if_green_enabled
.
source_branch
])
allow
(
ci_commit
).
to
receive
(
:success?
).
and_return
(
true
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:ci_commit
).
and_return
(
ci_commit
)
allow
(
ci_commit
).
to
receive
(
:success?
).
and_return
(
true
)
expect
(
MergeWorker
).
to
receive
(
:perform_async
)
service
.
trigger
(
commit_status
)
end
end
context
'properly handles multiple stages'
do
context
'properly handles multiple stages'
do
let
(
:ref
)
{
mr_merge_if_green_enabled
.
source_branch
}
let
(
:ref
)
{
mr_merge_if_green_enabled
.
source_branch
}
...
...
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