Commit 0f90fd63 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix/rename-mwbs-to-merge-when-pipeline-succeeds' into 'master'

Rename MWBS service to Merge When Pipeline Succeeds

## What does this MR do?

This MR renames Merge When Build Succeeds feature to Merge When Pipeline Succeeds, because we recently changed the behavior, see https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6675.

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG.md) entry added
- [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [x] All builds are passing

## What are the relevant issue numbers?

Closes #23354

See merge request !7135
parents ca075c91 4681ab1d
...@@ -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,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -331,8 +335,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end end
if @merge_request.head_pipeline.active? if @merge_request.head_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.head_pipeline.success? elsif @merge_request.head_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)
......
...@@ -131,14 +131,14 @@ module SystemNoteService ...@@ -131,14 +131,14 @@ module SystemNoteService
create_note(noteable: noteable, project: project, author: author, note: body) create_note(noteable: noteable, project: project, author: author, note: body)
end end
# Called when 'merge when build succeeds' is executed # Called when 'merge when pipeline succeeds' is executed
def merge_when_build_succeeds(noteable, project, author, last_commit) def merge_when_build_succeeds(noteable, project, author, last_commit)
body = "enabled an automatic merge when the build for #{last_commit.to_reference(project)} succeeds" body = "enabled an automatic merge when the pipeline for #{last_commit.to_reference(project)} succeeds"
create_note(noteable: noteable, project: project, author: author, note: body) create_note(noteable: noteable, project: project, author: author, note: body)
end end
# Called when 'merge when build succeeds' is canceled # Called when 'merge when pipeline succeeds' is canceled
def cancel_merge_when_build_succeeds(noteable, project, author) def cancel_merge_when_build_succeeds(noteable, project, author)
body = 'canceled the automatic merge' body = 'canceled the automatic merge'
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- if @pipeline && @pipeline.active? - if @pipeline && @pipeline.active?
%span.btn-group %span.btn-group
= button_tag class: "btn btn-create js-merge-button merge_when_build_succeeds" do = button_tag class: "btn btn-create js-merge-button merge_when_build_succeeds" do
Merge When Build Succeeds Merge When Pipeline Succeeds
- unless @project.only_allow_merge_if_build_succeeds? - unless @project.only_allow_merge_if_build_succeeds?
= button_tag class: "btn btn-success dropdown-toggle", 'data-toggle' => 'dropdown' do = button_tag class: "btn btn-success dropdown-toggle", 'data-toggle' => 'dropdown' do
= icon('caret-down') = icon('caret-down')
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
%li %li
= link_to "#", class: "merge_when_build_succeeds" do = link_to "#", class: "merge_when_build_succeeds" do
= icon('check fw') = icon('check fw')
Merge When Build Succeeds Merge When Pipeline Succeeds
%li %li
= link_to "#", class: "accept_merge_request" do = link_to "#", class: "accept_merge_request" do
= icon('warning fw') = icon('warning fw')
......
%h4 %h4
Set by #{link_to_member(@project, @merge_request.merge_user, avatar: true)} Set by #{link_to_member(@project, @merge_request.merge_user, avatar: true)}
to be merged automatically when the build succeeds. to be merged automatically when the pipeline succeeds.
%div %div
%p %p
= succeed '.' do = succeed '.' do
......
...@@ -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
......
---
title: Rename Merge When Build Succeeds to Merge When Pipeline Succeeds
merge_request: 7135
author:
...@@ -510,7 +510,7 @@ Parameters: ...@@ -510,7 +510,7 @@ Parameters:
} }
``` ```
## Cancel Merge When Build Succeeds ## Cancel Merge When Pipeline Succeeds
If you don't have permissions to accept this merge request - you'll get a `401` If you don't have permissions to accept this merge request - you'll get a `401`
......
...@@ -70,8 +70,8 @@ experience, refactors the existing code). Then: ...@@ -70,8 +70,8 @@ experience, refactors the existing code). Then:
- After a round of line notes, it can be helpful to post a summary note such as - After a round of line notes, it can be helpful to post a summary note such as
"LGTM :thumbsup:", or "Just a couple things to address." "LGTM :thumbsup:", or "Just a couple things to address."
- Avoid accepting a merge request before the build succeeds. Of course, "Merge - Avoid accepting a merge request before the build succeeds. Of course, "Merge
When Build Succeeds" (MWBS) is fine. When Pipeline Succeeds" (MWPS) is fine.
- If you set the MR to "Merge When Build Succeeds", you should take over - If you set the MR to "Merge When Pipeline Succeeds", you should take over
subsequent revisions for anything that would be spotted after that. subsequent revisions for anything that would be spotted after that.
## The right balance ## The right balance
......
...@@ -23,7 +23,7 @@ Create merge requests and review code. ...@@ -23,7 +23,7 @@ Create merge requests and review code.
- [Fork a project and contribute to it](../workflow/forking_workflow.md) - [Fork a project and contribute to it](../workflow/forking_workflow.md)
- [Create a new merge request](../gitlab-basics/add-merge-request.md) - [Create a new merge request](../gitlab-basics/add-merge-request.md)
- [Automatically close issues from merge requests](../user/project/issues/automatic_issue_closing.md) - [Automatically close issues from merge requests](../user/project/issues/automatic_issue_closing.md)
- [Automatically merge when your builds succeed](../user/project/merge_requests/merge_when_build_succeeds.md) - [Automatically merge when pipeline succeeds](../user/project/merge_requests/merge_when_pipeline_succeeds.md)
- [Revert any commit](../user/project/merge_requests/revert_changes.md) - [Revert any commit](../user/project/merge_requests/revert_changes.md)
- [Cherry-pick any commit](../user/project/merge_requests/cherry_pick_changes.md) - [Cherry-pick any commit](../user/project/merge_requests/cherry_pick_changes.md)
......
...@@ -19,14 +19,14 @@ in a merged merge requests or a commit. ...@@ -19,14 +19,14 @@ in a merged merge requests or a commit.
[Learn more about cherry-picking changes.](merge_requests/cherry_pick_changes.md) [Learn more about cherry-picking changes.](merge_requests/cherry_pick_changes.md)
## Merge when build succeeds ## Merge when pipeline succeeds
When reviewing a merge request that looks ready to merge but still has one or When reviewing a merge request that looks ready to merge but still has one or
more CI builds running, you can set it to be merged automatically when all more CI builds running, you can set it to be merged automatically when CI
builds succeed. This way, you don't have to wait for the builds to finish and pipeline succeeds. This way, you don't have to wait for the pipeline to finish
remember to merge the request manually. and remember to merge the request manually.
[Learn more about merging when build succeeds.](merge_requests/merge_when_build_succeeds.md) [Learn more about merging when pipeline succeeds.](merge_requests/merge_when_pipeline_succeeds.md)
## Resolve discussion comments in merge requests reviews ## Resolve discussion comments in merge requests reviews
......
# Merge When Build Succeeds This document was moved to [merge_when_pipeline_succeeds](merge_when_pipeline_succeeds.md).
When reviewing a merge request that looks ready to merge but still has one or >[Introduced][ce-7135] by the "Rename MWBS service to Merge When Pipeline Succeeds" change.
more CI builds running, you can set it to be merged automatically when the
builds pipeline succeed. This way, you don't have to wait for the builds to
finish and remember to merge the request manually.
![Enable](img/merge_when_build_succeeds_enable.png) [ce-7135]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7135
When you hit the "Merge When Build Succeeds" button, the status of the merge
request will be updated to represent the impending merge. If you cannot wait
for the pipeline to succeed and want to merge immediately, this option is
available in the dropdown menu on the right of the main button.
Both team developers and the author of the merge request have the option to
cancel the automatic merge if they find a reason why it shouldn't be merged
after all.
![Status](img/merge_when_build_succeeds_status.png)
When the pipeline succeeds, the merge request will automatically be merged.
When the pipeline fails, the author gets a chance to retry any failed builds,
or to push new commits to fix the failure.
When the builds are retried and succeed on the second try, the merge request
will automatically be merged after all. When the merge request is updated with
new commits, the automatic merge is automatically canceled to allow the new
changes to be reviewed.
## Only allow merge requests to be merged if the build succeeds
> **Note:**
You need to have builds configured to enable this feature.
You can prevent merge requests from being merged if their build did not succeed.
Navigate to your project's settings page, select the
**Only allow merge requests to be merged if the build succeeds** check box and
hit **Save** for the changes to take effect.
![Only allow merge if build succeeds settings](img/merge_when_build_succeeds_only_if_succeeds_settings.png)
From now on, every time the pipeline fails you will not be able to merge the
merge request from the UI, until you make all relevant builds pass.
![Only allow merge if build succeeds message](img/merge_when_build_succeeds_only_if_succeeds_msg.png)
# Merge When Pipeline Succeeds
When reviewing a merge request that looks ready to merge but still has one or
more CI builds running, you can set it to be merged automatically when the
builds pipeline succeeds. This way, you don't have to wait for the builds to
finish and remember to merge the request manually.
![Enable](img/merge_when_build_succeeds_enable.png)
When you hit the "Merge When Pipeline Succeeds" button, the status of the merge
request will be updated to represent the impending merge. If you cannot wait
for the pipeline to succeed and want to merge immediately, this option is
available in the dropdown menu on the right of the main button.
Both team developers and the author of the merge request have the option to
cancel the automatic merge if they find a reason why it shouldn't be merged
after all.
![Status](img/merge_when_build_succeeds_status.png)
When the pipeline succeeds, the merge request will automatically be merged.
When the pipeline fails, the author gets a chance to retry any failed builds,
or to push new commits to fix the failure.
When the builds are retried and succeed on the second try, the merge request
will automatically be merged after all. When the merge request is updated with
new commits, the automatic merge is automatically canceled to allow the new
changes to be reviewed.
## Only allow merge requests to be merged if the pipeline succeeds
> **Note:**
You need to have builds configured to enable this feature.
You can prevent merge requests from being merged if their pipeline did not succeed.
Navigate to your project's settings page, select the
**Only allow merge requests to be merged if the pipeline succeeds** check box and
hit **Save** for the changes to take effect.
![Only allow merge if pipeline succeeds settings](img/merge_when_build_succeeds_only_if_succeeds_settings.png)
From now on, every time the pipeline fails you will not be able to merge the
merge request from the UI, until you make all relevant builds pass.
![Only allow merge if pipeline succeeds message](img/merge_when_build_succeeds_only_if_succeeds_msg.png)
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
- [Merge Requests](../user/project/merge_requests.md) - [Merge Requests](../user/project/merge_requests.md)
- [Authorization for merge requests](../user/project/merge_requests/authorization_for_merge_requests.md) - [Authorization for merge requests](../user/project/merge_requests/authorization_for_merge_requests.md)
- [Cherry-pick changes](../user/project/merge_requests/cherry_pick_changes.md) - [Cherry-pick changes](../user/project/merge_requests/cherry_pick_changes.md)
- [Merge when build succeeds](../user/project/merge_requests/merge_when_build_succeeds.md) - [Merge when pipeline succeeds](../user/project/merge_requests/merge_when_pipeline_succeeds.md)
- [Resolve discussion comments in merge requests reviews](../user/project/merge_requests/merge_request_discussion_resolution.md) - [Resolve discussion comments in merge requests reviews](../user/project/merge_requests/merge_request_discussion_resolution.md)
- [Resolve merge conflicts in the UI](../user/project/merge_requests/resolve_conflicts.md) - [Resolve merge conflicts in the UI](../user/project/merge_requests/resolve_conflicts.md)
- [Revert changes in the UI](../user/project/merge_requests/revert_changes.md) - [Revert changes in the UI](../user/project/merge_requests/revert_changes.md)
- [Merge requests versions](../user/project/merge_requests/versions.md) - [Merge requests versions](../user/project/merge_requests/versions.md)
- ["Work In Progress" merge requests](../user/project/merge_requests/work_in_progress_merge_requests.md) - ["Work In Progress" merge requests](../user/project/merge_requests/work_in_progress_merge_requests.md)
- [Manage large binaries with Git LFS](lfs/manage_large_binaries_with_git_lfs.md) - [Manage large binaries with Git LFS](lfs/manage_large_binaries_with_git_lfs.md)
- [Importing from SVN, GitHub, BitBucket, etc](importing/README.md) - [Importing from SVN, GitHub, Bitbucket, etc](importing/README.md)
- [Todos](todos.md) - [Todos](todos.md)
This document was moved to [user/project/merge_requests/merge_when_build_succeeds](../user/project/merge_requests/merge_when_build_succeeds.md). This document was moved to [merge_when_pipeline_succeeds](../user/project/merge_requests/merge_when_pipeline_succeeds.md).
...@@ -169,7 +169,7 @@ module API ...@@ -169,7 +169,7 @@ module API
optional :should_remove_source_branch, type: Boolean, optional :should_remove_source_branch, type: Boolean,
desc: 'When true, the source branch will be deleted if possible' desc: 'When true, the source branch will be deleted if possible'
optional :merge_when_build_succeeds, type: Boolean, optional :merge_when_build_succeeds, type: Boolean,
desc: 'When true, this merge request will be merged when the build succeeds' desc: 'When true, this merge request will be merged when the pipeline succeeds'
optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch' optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch'
end end
put "#{path}/merge" do put "#{path}/merge" do
...@@ -193,17 +193,19 @@ module API ...@@ -193,17 +193,19 @@ module API
} }
if params[:merge_when_build_succeeds] && merge_request.head_pipeline && merge_request.head_pipeline.active? if params[:merge_when_build_succeeds] && merge_request.head_pipeline && merge_request.head_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
end end
desc 'Cancel merge if "Merge when build succeeds" is enabled' do desc 'Cancel merge if "Merge When Pipeline Succeeds" is enabled' do
success Entities::MergeRequest success Entities::MergeRequest
end end
post "#{path}/cancel_merge_when_build_succeeds" do post "#{path}/cancel_merge_when_build_succeeds" do
...@@ -211,7 +213,9 @@ module API ...@@ -211,7 +213,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'
feature 'Merge When Build Succeeds', feature: true, js: true do feature 'Merge When Pipeline Succeeds', :feature, :js do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
...@@ -18,7 +18,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do ...@@ -18,7 +18,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
before { project.team << [user, :master] } before { project.team << [user, :master] }
context 'when there is active build for merge request' do context 'when there is active pipeline for merge request' do
background do background do
create(:ci_build, pipeline: pipeline) create(:ci_build, pipeline: pipeline)
end end
...@@ -28,28 +28,28 @@ feature 'Merge When Build Succeeds', feature: true, js: true do ...@@ -28,28 +28,28 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
visit_merge_request(merge_request) visit_merge_request(merge_request)
end end
it 'displays the Merge When Build Succeeds button' do it 'displays the Merge When Pipeline Succeeds button' do
expect(page).to have_button "Merge When Build Succeeds" expect(page).to have_button "Merge When Pipeline Succeeds"
end end
context "Merge When Build succeeds enabled" do context "Merge When Pipeline Succeeds enabled" do
before do before do
click_button "Merge When Build Succeeds" click_button "Merge When Pipeline Succeeds"
end end
it 'activates Merge When Build Succeeds feature' do it 'activates Merge When Pipeline Succeeds feature' do
expect(page).to have_link "Cancel Automatic Merge" expect(page).to have_link "Cancel Automatic Merge"
expect(page).to have_content "Set by #{user.name} to be merged automatically when the build succeeds." expect(page).to have_content "Set by #{user.name} to be merged automatically when the pipeline succeeds."
expect(page).to have_content "The source branch will not be removed." expect(page).to have_content "The source branch will not be removed."
visit_merge_request(merge_request) # Needed to refresh the page visit_merge_request(merge_request) # Needed to refresh the page
expect(page).to have_content /enabled an automatic merge when the build for \h{8} succeeds/i expect(page).to have_content /enabled an automatic merge when the pipeline for \h{8} succeeds/i
end end
end end
end end
context 'when merge when build succeeds is enabled' do context 'when merge when pipeline succeeds is enabled' do
let(:merge_request) do let(:merge_request) do
create(:merge_request_with_diffs, :simple, source_project: project, create(:merge_request_with_diffs, :simple, source_project: project,
author: user, author: user,
...@@ -70,7 +70,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do ...@@ -70,7 +70,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
it 'allows to cancel the automatic merge' do it 'allows to cancel the automatic merge' do
click_link "Cancel Automatic Merge" click_link "Cancel Automatic Merge"
expect(page).to have_button "Merge When Build Succeeds" expect(page).to have_button "Merge When Pipeline Succeeds"
visit_merge_request(merge_request) # refresh the page visit_merge_request(merge_request) # refresh the page
expect(page).to have_content "canceled the automatic merge" expect(page).to have_content "canceled the automatic merge"
...@@ -83,7 +83,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do ...@@ -83,7 +83,7 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
expect(page).to have_content "The source branch will be removed" expect(page).to have_content "The source branch will be removed"
end end
context 'when build succeeds' do context 'when pipeline succeeds' do
background { build.success } background { build.success }
it 'merges merge request' do it 'merges merge request' do
...@@ -95,10 +95,11 @@ feature 'Merge When Build Succeeds', feature: true, js: true do ...@@ -95,10 +95,11 @@ feature 'Merge When Build Succeeds', feature: true, js: true do
end end
end end
context 'when build is not active' do context 'when pipeline is not active' do
it "does not allow to enable merge when build succeeds" do it "does not allow to enable merge when pipeline succeeds" do
visit_merge_request(merge_request) visit_merge_request(merge_request)
expect(page).not_to have_link "Merge When Build Succeeds"
expect(page).not_to have_link 'Merge When Pipeline Succeeds'
end end
end end
......
...@@ -38,7 +38,7 @@ feature 'Only allow merge requests to be merged if the build succeeds', feature: ...@@ -38,7 +38,7 @@ feature 'Only allow merge requests to be merged if the build succeeds', feature:
it 'does not allow to merge immediately' do it 'does not allow to merge immediately' do
visit_merge_request(merge_request) visit_merge_request(merge_request)
expect(page).to have_button 'Merge When Build Succeeds' expect(page).to have_button 'Merge When Pipeline Succeeds'
expect(page).not_to have_button 'Select Merge Moment' expect(page).not_to have_button 'Select Merge Moment'
end end
end end
...@@ -97,7 +97,7 @@ feature 'Only allow merge requests to be merged if the build succeeds', feature: ...@@ -97,7 +97,7 @@ feature 'Only allow merge requests to be merged if the build succeeds', feature:
it 'allows MR to be merged immediately', js: true do it 'allows MR to be merged immediately', js: true do
visit_merge_request(merge_request) visit_merge_request(merge_request)
expect(page).to have_button 'Merge When Build Succeeds' expect(page).to have_button 'Merge When Pipeline Succeeds'
click_button 'Select Merge Moment' click_button 'Select Merge Moment'
expect(page).to have_content 'Merge Immediately' expect(page).to have_content 'Merge Immediately'
......
...@@ -31,7 +31,7 @@ describe MergeRequest, models: true do ...@@ -31,7 +31,7 @@ describe MergeRequest, models: true do
it { is_expected.to validate_presence_of(:target_branch) } it { is_expected.to validate_presence_of(:target_branch) }
it { is_expected.to validate_presence_of(:source_branch) } it { is_expected.to validate_presence_of(:source_branch) }
context "Validation of merge user with Merge When Build succeeds" do context "Validation of merge user with Merge When Pipeline Succeeds" do
it "allows user to be nil when the feature is disabled" do it "allows user to be nil when the feature is disabled" do
expect(subject).to be_valid expect(subject).to be_valid
end end
......
...@@ -465,7 +465,7 @@ describe API::MergeRequests, api: true do ...@@ -465,7 +465,7 @@ describe API::MergeRequests, api: true do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
it "enables merge when build succeeds if the ci is active" do it "enables merge when pipeline succeeds if the pipeline is active" do
allow_any_instance_of(MergeRequest).to receive(:head_pipeline).and_return(pipeline) allow_any_instance_of(MergeRequest).to receive(:head_pipeline).and_return(pipeline)
allow(pipeline).to receive(:active?).and_return(true) allow(pipeline).to receive(:active?).and_return(true)
......
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
...@@ -37,12 +43,12 @@ describe MergeRequests::MergeWhenBuildSucceedsService do ...@@ -37,12 +43,12 @@ describe MergeRequests::MergeWhenBuildSucceedsService do
it 'creates a system note' do it 'creates a system note' do
note = merge_request.notes.last note = merge_request.notes.last
expect(note.note).to match /enabled an automatic merge when the build for (\w+\/\w+@)?\h{8}/ expect(note.note).to match /enabled an automatic merge when the pipeline for (\w+\/\w+@)?\h{8}/
end end
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
......
...@@ -225,8 +225,8 @@ describe SystemNoteService, services: true do ...@@ -225,8 +225,8 @@ describe SystemNoteService, services: true do
it_behaves_like 'a system note' it_behaves_like 'a system note'
it "posts the Merge When Build Succeeds system note" do it "posts the 'merge when pipeline succeeds' system note" do
expect(subject.note).to match /enabled an automatic merge when the build for (\w+\/\w+@)?\h{40} succeeds/ expect(subject.note).to match /enabled an automatic merge when the pipeline for (\w+\/\w+@)?\h{40} succeeds/
end end
end end
...@@ -239,7 +239,7 @@ describe SystemNoteService, services: true do ...@@ -239,7 +239,7 @@ describe SystemNoteService, services: true do
it_behaves_like 'a system note' it_behaves_like 'a system note'
it "posts the Merge When Build Succeeds system note" do it "posts the 'merge when pipeline succeeds' system note" do
expect(subject.note).to eq "canceled the automatic merge" expect(subject.note).to eq "canceled the automatic merge"
end end
end end
......
...@@ -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