Commit b6c8d3ac authored by Matija Čupić's avatar Matija Čupić

Reintroduce Command#protected_ref?

parent b0b5924e
......@@ -17,6 +17,7 @@ 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)
)
......
......@@ -51,6 +51,12 @@ module Gitlab
def before_sha
self[:before_sha] || checkout_sha || Gitlab::Git::BLANK_SHA
end
def protected_ref?
strong_memoize(:protected_ref) do
project.protected_for?(origin_ref)
end
end
end
end
end
......
......@@ -18,11 +18,6 @@ module Gitlab
#
@command.seeds_block&.call(pipeline)
##
# Populate pipeline protected status
#
pipeline.protected = @command.project.protected_for?(@command.origin_ref)
##
# Populate pipeline with all stages, and stages with builds.
#
......
......@@ -31,7 +31,7 @@ module Gitlab
if current_user
allowed_to_create?
else # legacy triggers don't have a corresponding user
!@command.project.protected_for?(@command.origin_ref)
!@command.protected_ref?
end
end
......
......@@ -54,11 +54,11 @@ module Gitlab
end
def tag_ref?(ref)
ref.start_with?(TAG_REF_PREFIX)
ref =~ %r{#{TAG_REF_PREFIX}\w+}
end
def branch_ref?(ref)
ref.start_with?(BRANCH_REF_PREFIX)
ref =~ %r{#{BRANCH_REF_PREFIX}\w+}
end
def blank_ref?(ref)
......
......@@ -160,4 +160,26 @@ describe Gitlab::Ci::Pipeline::Chain::Command do
end
end
end
describe '#protected_ref?' do
let(:command) { described_class.new(project: project, origin_ref: 'my-branch') }
subject { command.protected_ref? }
context 'when a ref is protected' do
before do
expect_any_instance_of(Project).to receive(:protected_for?).with('my-branch').and_return(true)
end
it { is_expected.to eq(true) }
end
context 'when a ref is unprotected' do
before do
expect_any_instance_of(Project).to receive(:protected_for?).with('my-branch').and_return(false)
end
it { is_expected.to eq(false) }
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Pipeline::Seed::Build do
let(:pipeline) { create(:ci_empty_pipeline) }
let(:project) { create(:project, :repository) }
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:attributes) do
{ name: 'rspec',
......
require 'spec_helper'
describe Gitlab::Ci::Pipeline::Seed::Stage do
let(:pipeline) { create(:ci_empty_pipeline) }
let(:project) { create(:project, :repository) }
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:attributes) do
{ name: 'test',
......
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