Commit e0efa97c authored by Shinya Maeda's avatar Shinya Maeda

Prevent triggering pipelines when target branch is updated

Currently, pipelines for merge requests are triggered when source or
target branch is updated. However, we should create only when source
branch is updated, because it runs unexpected pipelines.
parent dfb26f00
...@@ -21,6 +21,7 @@ module MergeRequests ...@@ -21,6 +21,7 @@ module MergeRequests
post_merge_manually_merged post_merge_manually_merged
reload_merge_requests reload_merge_requests
outdate_suggestions outdate_suggestions
refresh_pipelines_on_merge_requests
reset_merge_when_pipeline_succeeds reset_merge_when_pipeline_succeeds
mark_pending_todos_done mark_pending_todos_done
cache_merge_requests_closing_issues cache_merge_requests_closing_issues
...@@ -107,8 +108,6 @@ module MergeRequests ...@@ -107,8 +108,6 @@ module MergeRequests
end end
merge_request.mark_as_unchecked merge_request.mark_as_unchecked
create_pipeline_for(merge_request, current_user)
UpdateHeadPipelineForMergeRequestWorker.perform_async(merge_request.id)
end end
# Upcoming method calls need the refreshed version of # Upcoming method calls need the refreshed version of
...@@ -134,6 +133,13 @@ module MergeRequests ...@@ -134,6 +133,13 @@ module MergeRequests
end end
end end
def refresh_pipelines_on_merge_requests
merge_requests_for_source_branch.each do |merge_request|
create_pipeline_for(merge_request, current_user)
UpdateHeadPipelineForMergeRequestWorker.perform_async(merge_request.id)
end
end
def reset_merge_when_pipeline_succeeds def reset_merge_when_pipeline_succeeds
merge_requests_for_source_branch.each(&:reset_merge_when_pipeline_succeeds) merge_requests_for_source_branch.each(&:reset_merge_when_pipeline_succeeds)
end end
......
---
title: Create pipelines for merge requests only when source branch is updated
merge_request: 26921
author:
type: fixed
...@@ -146,7 +146,10 @@ describe MergeRequests::RefreshService do ...@@ -146,7 +146,10 @@ describe MergeRequests::RefreshService do
stub_ci_pipeline_yaml_file(YAML.dump(config)) stub_ci_pipeline_yaml_file(YAML.dump(config))
end end
subject { service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/master') } subject { service.new(project, @user).execute(@oldrev, @newrev, ref) }
let(:ref) { 'refs/heads/master' }
let(:project) { @project }
context "when .gitlab-ci.yml has merge_requests keywords" do context "when .gitlab-ci.yml has merge_requests keywords" do
let(:config) do let(:config) do
...@@ -162,14 +165,17 @@ describe MergeRequests::RefreshService do ...@@ -162,14 +165,17 @@ describe MergeRequests::RefreshService do
it 'create detached merge request pipeline with commits' do it 'create detached merge request pipeline with commits' do
expect { subject } expect { subject }
.to change { @merge_request.merge_request_pipelines.count }.by(1) .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(0) .and change { @another_merge_request.merge_request_pipelines.count }.by(0)
expect(@merge_request.has_commits?).to be_truthy 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 expect(@another_merge_request.has_commits?).to be_falsy
end end
it 'does not create detached merge request pipeline for forked project' do
expect { subject }
.not_to change { @fork_merge_request.merge_request_pipelines.count }
end
it 'create detached merge request pipeline for non-fork merge request' do it 'create detached merge request pipeline for non-fork merge request' do
subject subject
...@@ -177,11 +183,25 @@ describe MergeRequests::RefreshService do ...@@ -177,11 +183,25 @@ describe MergeRequests::RefreshService do
.to be_detached_merge_request_pipeline .to be_detached_merge_request_pipeline
end end
it 'create legacy detached merge request pipeline for fork merge request' do context 'when service is hooked by target branch' do
subject let(:ref) { 'refs/heads/feature' }
expect(@fork_merge_request.merge_request_pipelines.first) it 'does not create detached merge request pipeline' do
.to be_legacy_detached_merge_request_pipeline expect { subject }
.not_to change { @merge_request.merge_request_pipelines.count }
end
end
context 'when service runs on forked project' do
let(:project) { @fork_project }
it 'creates legacy detached merge request pipeline for fork merge request' do
expect { subject }
.to change { @fork_merge_request.merge_request_pipelines.count }.by(1)
expect(@fork_merge_request.merge_request_pipelines.first)
.to be_legacy_detached_merge_request_pipeline
end
end end
context 'when ci_use_merge_request_ref feature flag is false' do context 'when ci_use_merge_request_ref feature flag is false' 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