BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
01f23889
Commit
01f23889
authored
Oct 27, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename MWBS service to Merge When Pipeline Succeeds
parent
900999f8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
17 deletions
+34
-17
merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+9
-4
merge_when_pipeline_succeeds_service.rb
...es/merge_requests/merge_when_pipeline_succeeds_service.rb
+1
-1
pipeline_success_worker.rb
app/workers/pipeline_success_worker.rb
+1
-1
merge_requests.rb
lib/api/merge_requests.rb
+9
-5
merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+3
-1
merge_when_pipeline_succeeds_service_spec.rb
...rge_requests/merge_when_pipeline_succeeds_service_spec.rb
+10
-4
pipeline_success_worker_spec.rb
spec/workers/pipeline_success_worker_spec.rb
+1
-1
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
01f23889
...
...
@@ -302,9 +302,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def
cancel_merge_when_build_succeeds
return
access_denied!
unless
@merge_request
.
can_cancel_merge_when_build_succeeds?
(
current_user
)
unless
@merge_request
.
can_cancel_merge_when_build_succeeds?
(
current_user
)
return
access_denied!
end
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
@project
,
current_user
).
cancel
(
@merge_request
)
MergeRequests
::
MergeWhenPipelineSucceedsService
.
new
(
@project
,
current_user
)
.
cancel
(
@merge_request
)
end
def
merge
...
...
@@ -331,8 +335,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
if
@merge_request
.
pipeline
.
active?
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
@project
,
current_user
,
merge_params
)
.
execute
(
@merge_request
)
MergeRequests
::
MergeWhenPipelineSucceedsService
.
new
(
@project
,
current_user
,
merge_params
)
.
execute
(
@merge_request
)
@status
=
:merge_when_build_succeeds
elsif
@merge_request
.
pipeline
.
success?
# This can be triggered when a user clicks the auto merge button while
...
...
app/services/merge_requests/merge_when_
build
_succeeds_service.rb
→
app/services/merge_requests/merge_when_
pipeline
_succeeds_service.rb
View file @
01f23889
module
MergeRequests
class
MergeWhen
Build
SucceedsService
<
MergeRequests
::
BaseService
class
MergeWhen
Pipeline
SucceedsService
<
MergeRequests
::
BaseService
# Marks the passed `merge_request` to be merged when the build succeeds or
# updates the params for the automatic merge
def
execute
(
merge_request
)
...
...
app/workers/pipeline_success_worker.rb
View file @
01f23889
...
...
@@ -4,7 +4,7 @@ class PipelineSuccessWorker
def
perform
(
pipeline_id
)
Ci
::
Pipeline
.
find_by
(
id:
pipeline_id
).
try
do
|
pipeline
|
MergeRequests
::
MergeWhen
Build
SucceedsService
MergeRequests
::
MergeWhen
Pipeline
SucceedsService
.
new
(
pipeline
.
project
,
nil
)
.
trigger
(
pipeline
)
end
...
...
lib/api/merge_requests.rb
View file @
01f23889
...
...
@@ -205,11 +205,13 @@ module API
}
if
params
[
:merge_when_build_succeeds
]
&&
merge_request
.
pipeline
&&
merge_request
.
pipeline
.
active?
::
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
merge_request
.
target_project
,
current_user
,
merge_params
).
execute
(
merge_request
)
::
MergeRequests
::
MergeWhenPipelineSucceedsService
.
new
(
merge_request
.
target_project
,
current_user
,
merge_params
)
.
execute
(
merge_request
)
else
::
MergeRequests
::
MergeService
.
new
(
merge_request
.
target_project
,
current_user
,
merge_params
).
execute
(
merge_request
)
::
MergeRequests
::
MergeService
.
new
(
merge_request
.
target_project
,
current_user
,
merge_params
)
.
execute
(
merge_request
)
end
present
merge_request
,
with:
Entities
::
MergeRequest
,
current_user:
current_user
,
project:
user_project
...
...
@@ -223,7 +225,9 @@ module API
unauthorized!
unless
merge_request
.
can_cancel_merge_when_build_succeeds?
(
current_user
)
::
MergeRequest
::
MergeWhenBuildSucceedsService
.
new
(
merge_request
.
target_project
,
current_user
).
cancel
(
merge_request
)
::
MergeRequest
::
MergeWhenPipelineSucceedsService
.
new
(
merge_request
.
target_project
,
current_user
)
.
cancel
(
merge_request
)
end
desc
'Get the comments of a merge request'
do
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
01f23889
...
...
@@ -292,7 +292,9 @@ describe Projects::MergeRequestsController do
it
'sets the MR to merge when the build succeeds'
do
service
=
double
(
:merge_when_build_succeeds_service
)
expect
(
MergeRequests
::
MergeWhenBuildSucceedsService
).
to
receive
(
:new
).
with
(
project
,
anything
,
anything
).
and_return
(
service
)
expect
(
MergeRequests
::
MergeWhenPipelineSucceedsService
)
.
to
receive
(
:new
).
with
(
project
,
anything
,
anything
)
.
and_return
(
service
)
expect
(
service
).
to
receive
(
:execute
).
with
(
merge_request
)
merge_when_build_succeeds
...
...
spec/services/merge_requests/merge_when_
build
_succeeds_service_spec.rb
→
spec/services/merge_requests/merge_when_
pipeline
_succeeds_service_spec.rb
View file @
01f23889
require
'spec_helper'
describe
MergeRequests
::
MergeWhen
Build
SucceedsService
do
describe
MergeRequests
::
MergeWhen
Pipeline
SucceedsService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
...
...
@@ -10,8 +10,14 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
source_project:
project
,
target_project:
project
,
state:
"opened"
)
end
let
(
:pipeline
)
{
create
(
:ci_pipeline_with_one_job
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
project:
project
)
}
let
(
:service
)
{
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
}
let
(
:pipeline
)
do
create
(
:ci_pipeline_with_one_job
,
ref:
mr_merge_if_green_enabled
.
source_branch
,
project:
project
)
end
let
(
:service
)
do
described_class
.
new
(
project
,
user
,
commit_message:
'Awesome message'
)
end
describe
"#execute"
do
let
(
:merge_request
)
do
...
...
@@ -39,7 +45,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
end
context
'already approved'
do
let
(
:service
)
{
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
project
,
user
,
new_key:
true
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
new_key:
true
)
}
let
(
:build
)
{
create
(
:ci_build
,
ref:
mr_merge_if_green_enabled
.
source_branch
)
}
before
do
...
...
spec/workers/pipeline_success_worker_spec.rb
View file @
01f23889
...
...
@@ -7,7 +7,7 @@ describe PipelineSuccessWorker do
it
'performs "merge when pipeline succeeds"'
do
expect_any_instance_of
(
MergeRequests
::
MergeWhen
Build
SucceedsService
MergeRequests
::
MergeWhen
Pipeline
SucceedsService
).
to
receive
(
:trigger
)
described_class
.
new
.
perform
(
pipeline
.
id
)
...
...
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