BigW Consortium Gitlab

Commit 01f23889 by Grzegorz Bizon

Rename MWBS service to Merge When Pipeline Succeeds

parent 900999f8
...@@ -302,9 +302,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -302,9 +302,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
def cancel_merge_when_build_succeeds 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 end
def merge def merge
...@@ -331,8 +335,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -331,8 +335,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
if @merge_request.pipeline.active? if @merge_request.pipeline.active?
MergeRequests::MergeWhenBuildSucceedsService.new(@project, current_user, merge_params) MergeRequests::MergeWhenPipelineSucceedsService
.execute(@merge_request) .new(@project, current_user, merge_params)
.execute(@merge_request)
@status = :merge_when_build_succeeds @status = :merge_when_build_succeeds
elsif @merge_request.pipeline.success? elsif @merge_request.pipeline.success?
# This can be triggered when a user clicks the auto merge button while # This can be triggered when a user clicks the auto merge button while
......
module MergeRequests module MergeRequests
class MergeWhenBuildSucceedsService < MergeRequests::BaseService class MergeWhenPipelineSucceedsService < MergeRequests::BaseService
# Marks the passed `merge_request` to be merged when the build succeeds or # Marks the passed `merge_request` to be merged when the build succeeds or
# updates the params for the automatic merge # updates the params for the automatic merge
def execute(merge_request) def execute(merge_request)
......
...@@ -4,7 +4,7 @@ class PipelineSuccessWorker ...@@ -4,7 +4,7 @@ class PipelineSuccessWorker
def perform(pipeline_id) def perform(pipeline_id)
Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline| Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline|
MergeRequests::MergeWhenBuildSucceedsService MergeRequests::MergeWhenPipelineSucceedsService
.new(pipeline.project, nil) .new(pipeline.project, nil)
.trigger(pipeline) .trigger(pipeline)
end end
......
...@@ -205,11 +205,13 @@ module API ...@@ -205,11 +205,13 @@ module API
} }
if params[:merge_when_build_succeeds] && merge_request.pipeline && merge_request.pipeline.active? if params[:merge_when_build_succeeds] && merge_request.pipeline && merge_request.pipeline.active?
::MergeRequests::MergeWhenBuildSucceedsService.new(merge_request.target_project, current_user, merge_params). ::MergeRequests::MergeWhenPipelineSucceedsService
execute(merge_request) .new(merge_request.target_project, current_user, merge_params)
.execute(merge_request)
else else
::MergeRequests::MergeService.new(merge_request.target_project, current_user, merge_params). ::MergeRequests::MergeService
execute(merge_request) .new(merge_request.target_project, current_user, merge_params)
.execute(merge_request)
end end
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
...@@ -223,7 +225,9 @@ module API ...@@ -223,7 +225,9 @@ module API
unauthorized! unless merge_request.can_cancel_merge_when_build_succeeds?(current_user) 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 end
desc 'Get the comments of a merge request' do desc 'Get the comments of a merge request' do
......
...@@ -292,7 +292,9 @@ describe Projects::MergeRequestsController do ...@@ -292,7 +292,9 @@ describe Projects::MergeRequestsController do
it 'sets the MR to merge when the build succeeds' do it 'sets the MR to merge when the build succeeds' do
service = double(:merge_when_build_succeeds_service) 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) expect(service).to receive(:execute).with(merge_request)
merge_when_build_succeeds merge_when_build_succeeds
......
require 'spec_helper' require 'spec_helper'
describe MergeRequests::MergeWhenBuildSucceedsService do describe MergeRequests::MergeWhenPipelineSucceedsService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
...@@ -10,8 +10,14 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -10,8 +10,14 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
source_project: project, target_project: project, state: "opened") source_project: project, target_project: project, state: "opened")
end end
let(:pipeline) { create(:ci_pipeline_with_one_job, ref: mr_merge_if_green_enabled.source_branch, project: project) } let(:pipeline) do
let(:service) { MergeRequests::MergeWhenBuildSucceedsService.new(project, user, commit_message: 'Awesome message') } 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 describe "#execute" do
let(:merge_request) do let(:merge_request) do
...@@ -39,7 +45,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -39,7 +45,7 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
end end
context 'already approved' do 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) } let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch) }
before do before do
......
...@@ -7,7 +7,7 @@ describe PipelineSuccessWorker do ...@@ -7,7 +7,7 @@ describe PipelineSuccessWorker do
it 'performs "merge when pipeline succeeds"' do it 'performs "merge when pipeline succeeds"' do
expect_any_instance_of( expect_any_instance_of(
MergeRequests::MergeWhenBuildSucceedsService MergeRequests::MergeWhenPipelineSucceedsService
).to receive(:trigger) ).to receive(:trigger)
described_class.new.perform(pipeline.id) described_class.new.perform(pipeline.id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment