Commit fb296ab5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

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
parents 97342325 348e346d
......@@ -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)
......
---
title: Don't create new merge request pipeline without commits
merge_request: 24503
author: Hiroyuki Sato
type: added
......@@ -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,
......
......@@ -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
......
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