Commit 1ae99076 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'raise-exception-when-non-dangling-build-uses-parameter-source-224135' into 'master'

Raise error when non-dangling builds use YAML blob

See merge request gitlab-org/gitlab!35825
parents d0b3eb06 0910f60a
......@@ -90,6 +90,10 @@ module Gitlab
metrics.pipeline_size_histogram
.observe({ source: pipeline.source.to_s }, pipeline.total_size)
end
def dangling_build?
%i[ondemand_dast_scan webide].include?(source)
end
end
end
end
......
......@@ -7,9 +7,12 @@ module Gitlab
module Config
class Content
class Parameter < Source
UnsupportedSourceError = Class.new(StandardError)
def content
strong_memoize(:content) do
next unless command.content.present?
raise UnsupportedSourceError, "#{command.source} not a dangling build" unless command.dangling_build?
command.content
end
......
......@@ -270,4 +270,29 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Command do
it { is_expected. to eq(true) }
end
end
describe '#dangling_build?' do
let(:project) { create(:project, :repository) }
let(:command) { described_class.new(project: project, source: source) }
subject { command.dangling_build? }
context 'when source is :webide' do
let(:source) { :webide }
it { is_expected.to eq(true) }
end
context 'when source is :ondemand_dast_scan' do
let(:source) { :ondemand_dast_scan }
it { is_expected.to eq(true) }
end
context 'when source something else' do
let(:source) { :web }
it { is_expected.to eq(false) }
end
end
end
......@@ -6,7 +6,8 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Config::Content do
let(:project) { create(:project, ci_config_path: ci_config_path) }
let(:pipeline) { build(:ci_pipeline, project: project) }
let(:content) { nil }
let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new(project: project, content: content) }
let(:source) { :push }
let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new(project: project, content: content, source: source) }
subject { described_class.new(pipeline, command) }
......@@ -143,6 +144,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Config::Content do
end
context 'when config is passed as a parameter' do
let(:source) { :ondemand_dast_scan }
let(:ci_config_path) { nil }
let(:content) do
<<~EOY
......
......@@ -28,7 +28,8 @@ RSpec.describe Ci::CreatePipelineService do
end
describe '#execute' do
subject { service.execute(:web, content: content) }
context 'when source is a dangling build' do
subject { service.execute(:ondemand_dast_scan, content: content) }
context 'parameter config content' do
it 'creates a pipeline' do
......@@ -48,4 +49,14 @@ RSpec.describe Ci::CreatePipelineService do
end
end
end
context 'when source is not a dangling build' do
subject { service.execute(:web, content: content) }
it 'raises an exception' do
klass = Gitlab::Ci::Pipeline::Chain::Config::Content::Parameter::UnsupportedSourceError
expect { subject }.to raise_error(klass)
end
end
end
end
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