Merge branch 'not-run-pipeline-on-empty-merge-request' into 'master'

Don't create new pipeline for merge requests with no commits

See merge request gitlab-org/gitlab-ce!24503
This commit is contained in:
Grzegorz Bizon 2019-02-05 13:01:18 +00:00
commit fb296ab571
4 changed files with 30 additions and 2 deletions

View file

@ -63,6 +63,7 @@ module MergeRequests
# UpdateMergeRequestsWorker could be retried by an exception.
# MR pipelines should not be recreated in such case.
return if merge_request.merge_request_pipeline_exists?
return if merge_request.has_no_commits?
Ci::CreatePipelineService
.new(merge_request.source_project, user, ref: merge_request.source_branch)

View file

@ -0,0 +1,5 @@
---
title: Don't create new merge request pipeline without commits
merge_request: 24503
author: Hiroyuki Sato
type: added

View file

@ -197,6 +197,24 @@ describe MergeRequests::CreateService do
expect(merge_request.actual_head_pipeline).to be_merge_request
end
context 'when there are no commits between source branch and target branch' do
let(:opts) do
{
title: 'Awesome merge_request',
description: 'please fix',
source_branch: 'not-merged-branch',
target_branch: 'master'
}
end
it 'does not create a merge request pipeline' do
expect(merge_request).to be_persisted
merge_request.reload
expect(merge_request.merge_request_pipelines.count).to eq(0)
end
end
context "when branch pipeline was created before a merge request pipline has been created" do
before do
create(:ci_pipeline, project: merge_request.source_project,

View file

@ -150,11 +150,15 @@ describe MergeRequests::RefreshService do
}
end
it 'create merge request pipeline' do
it 'create merge request pipeline with commits' do
expect { subject }
.to change { @merge_request.merge_request_pipelines.count }.by(1)
.and change { @fork_merge_request.merge_request_pipelines.count }.by(1)
.and change { @another_merge_request.merge_request_pipelines.count }.by(1)
.and change { @another_merge_request.merge_request_pipelines.count }.by(0)
expect(@merge_request.has_commits?).to be_truthy
expect(@fork_merge_request.has_commits?).to be_truthy
expect(@another_merge_request.has_commits?).to be_falsy
end
context "when branch pipeline was created before a merge request pipline has been created" do