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
Tatuya Kamada
gitlab-ce
Commits
9824a69c
Commit
9824a69c
authored
Oct 06, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests and code for MWBS event move to pipeline
parent
21724407
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
23 deletions
+31
-23
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+6
-0
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
.../merge_requests/merge_when_build_succeeds_service_spec.rb
+25
-23
No files found.
app/services/merge_requests/base_service.rb
View file @
9824a69c
...
...
@@ -56,12 +56,18 @@ module MergeRequests
def
pipeline_merge_requests
(
pipeline
)
merge_requests_for
(
pipeline
.
ref
,
pipeline
.
sha
).
each
do
|
merge_request
|
next
unless
pipeline
==
merge_request
.
pipeline
yield
merge_request
end
end
def
commit_status_merge_requests
(
commit_status
)
merge_requests_for
(
commit_status
.
ref
,
commit_status
.
sha
).
each
do
|
merge_request
|
pipeline
=
merge_request
.
pipeline
next
unless
pipeline
next
unless
pipeline
.
sha
==
commit_status
.
sha
yield
merge_request
end
end
...
...
spec/services/merge_requests/merge_when_build_succeeds_service_spec.rb
View file @
9824a69c
...
...
@@ -58,42 +58,44 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
end
describe
"#trigger"
do
context
'build with ref'
do
let
(
:build
)
{
create
(
:ci_build
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
status:
"success"
)
}
let
(
:merge_request_ref
)
{
mr_merge_if_green_enabled
.
source_branch
}
let
(
:merge_request_head
)
do
project
.
commit
(
mr_merge_if_green_enabled
.
source_branch
).
id
end
it
"merges all merge requests with merge when build succeeds enabled"
do
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:pipeline
).
and_return
(
pipeline
)
allow
(
pipeline
).
to
receive
(
:success?
).
and_return
(
true
)
context
'when triggered by pipeline with valid ref and sha'
do
let
(
:triggering_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
ref:
merge_request_ref
,
sha:
merge_request_head
,
status:
'success'
)
end
it
"merges all merge requests with merge when build succeeds enabled"
do
expect
(
MergeWorker
).
to
receive
(
:perform_async
)
service
.
trigger
(
build
)
service
.
trigger
(
triggering_pipeline
)
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
(
:pipeline
).
and_return
(
pipeline
)
allow
(
pipeline
).
to
receive
(
:success?
).
and_return
(
true
)
allow
(
old_build
).
to
receive
(
:sha
).
and_return
(
'1234abcdef'
)
context
'when triggered by an old pipeline'
do
let
(
:old_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
ref:
merge_request_ref
,
sha:
'1234abcdef'
,
status:
'success'
)
end
it
'it does not merge merge request'
do
expect
(
MergeWorker
).
not_to
receive
(
:perform_async
)
service
.
trigger
(
old_
build
)
service
.
trigger
(
old_
pipeline
)
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
([])
context
'when triggered by pipeline from a different branch'
do
let
(
:unrelated_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
ref:
'feature'
,
sha:
merge_request_head
,
status:
'success'
)
end
it
'does not merge request'
do
expect
(
MergeWorker
).
not_to
receive
(
:perform_async
)
service
.
trigger
(
commit_status
)
service
.
trigger
(
unrelated_pipeline
)
end
it
'discovers branches and merges all merge requests when status is success'
do
...
...
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