Commit f02be29e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '55966-when-ref-is-ambiguous-createpipelineservice-raises-an-error' into 'master'

Resolve "When ref is ambiguous, `CreatePipelineService` raises an error"

Closes #55966

See merge request gitlab-org/gitlab-ce!24437
parents 7b6fa5ff a2477ec2
---
title: Prevent checking protected_ref? for ambiguous refs.
merge_request: 24437
author:
type: fixed
......@@ -17,7 +17,6 @@ module Gitlab
user: @command.current_user,
pipeline_schedule: @command.schedule,
merge_request: @command.merge_request,
protected: @command.protected_ref?,
variables_attributes: Array(@command.variables_attributes)
)
......
......@@ -13,6 +13,10 @@ module Gitlab
# Allocate next IID. This operation must be outside of transactions of pipeline creations.
pipeline.ensure_project_iid!
# Protect the pipeline. This is assigned in Populate instead of
# Build to prevent erroring out on ambiguous refs.
pipeline.protected = @command.protected_ref?
##
# Populate pipeline with block argument of CreatePipelineService#execute.
#
......
......@@ -79,6 +79,31 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
end
end
describe 'pipeline protect' do
subject { step.perform! }
context 'when ref is protected' do
before do
allow(project).to receive(:protected_for?).with('master').and_return(true)
allow(project).to receive(:protected_for?).with('refs/heads/master').and_return(true)
end
it 'does not protect the pipeline' do
subject
expect(pipeline.protected).to eq(true)
end
end
context 'when ref is not protected' do
it 'does not protect the pipeline' do
subject
expect(pipeline.protected).to eq(false)
end
end
end
context 'when pipeline has validation errors' do
let(:pipeline) do
build(:ci_pipeline, project: project, ref: nil)
......
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