Commit 9d1c1d54 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Reduce stage seeds coupling between pipeline and YAML

This is a first step to decouple pipeline from YAML processing. It
reduces the coupling by removing some methods that introduce coupling
and by moving logic into separate chain element that is being used to
populate pipelines with stages and builds.

Conflicts:
	spec/models/ci/pipeline_spec.rb
parent f5cf26d4
...@@ -379,18 +379,10 @@ module Ci ...@@ -379,18 +379,10 @@ module Ci
@stage_seeds ||= config_processor.stage_seeds(self) @stage_seeds ||= config_processor.stage_seeds(self)
end end
def seeds_size
@seeds_size ||= stage_seeds.sum(&:size)
end
def has_kubernetes_active? def has_kubernetes_active?
project.deployment_platform&.active? project.deployment_platform&.active?
end end
def has_stage_seeds?
stage_seeds.any?
end
def has_warnings? def has_warnings?
builds.latest.failed_but_allowed.any? builds.latest.failed_but_allowed.any?
end end
......
...@@ -21,15 +21,19 @@ module Gitlab ...@@ -21,15 +21,19 @@ module Gitlab
pipeline.stages << seed.to_resource pipeline.stages << seed.to_resource
end end
if pipeline.stages.none?
return error('No stages / jobs for this pipeline.')
end
if pipeline.invalid? if pipeline.invalid?
error('Failed to build the pipeline!') return error('Failed to build the pipeline!')
end end
raise Populate::PopulateError if pipeline.persisted? raise Populate::PopulateError if pipeline.persisted?
end end
def break? def break?
pipeline.invalid? pipeline.errors.any?
end end
end end
end end
......
...@@ -18,10 +18,6 @@ module Gitlab ...@@ -18,10 +18,6 @@ module Gitlab
return error(@pipeline.yaml_errors) return error(@pipeline.yaml_errors)
end end
unless @pipeline.has_stage_seeds?
return error('No stages / jobs for this pipeline.')
end
end end
def break? def break?
......
...@@ -42,6 +42,32 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do ...@@ -42,6 +42,32 @@ describe Gitlab::Ci::Pipeline::Chain::Populate do
end end
end end
context 'when pipeline is empty' do
let(:config) do
{ rspec: {
script: 'ls',
only: ['something']
} }
end
let(:pipeline) do
build(:ci_pipeline, project: project, config: config)
end
before do
step.perform!
end
it 'breaks the chain' do
expect(step.break?).to be true
end
it 'appends an error about missing stages' do
expect(pipeline.errors.to_a)
.to include 'No stages / jobs for this pipeline.'
end
end
context 'when pipeline has validation errors' do context 'when pipeline has validation errors' do
let(:pipeline) do let(:pipeline) do
build(:ci_pipeline, project: project, ref: nil) build(:ci_pipeline, project: project, ref: nil)
......
...@@ -76,28 +76,6 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do ...@@ -76,28 +76,6 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
end end
end end
context 'when pipeline has no stages / jobs' do
let(:config) do
{ rspec: {
script: 'ls',
only: ['something']
} }
end
let(:pipeline) do
build(:ci_pipeline, project: project, config: config)
end
it 'appends an error about missing stages' do
expect(pipeline.errors.to_a)
.to include 'No stages / jobs for this pipeline.'
end
it 'breaks the chain' do
expect(step.break?).to be true
end
end
context 'when pipeline contains configuration validation errors' do context 'when pipeline contains configuration validation errors' do
let(:config) { { rspec: {} } } let(:config) { { rspec: {} } }
......
...@@ -258,15 +258,6 @@ describe Ci::Pipeline, :mailer do ...@@ -258,15 +258,6 @@ describe Ci::Pipeline, :mailer do
end end
end end
describe '#seeds_size' do
let(:project) { create(:project, :repository) }
let(:pipeline) { build(:ci_pipeline_with_one_job, project: project) }
it 'returns number of jobs in stage seeds' do
expect(pipeline.seeds_size).to eq 1
end
end
describe '#legacy_stages' do describe '#legacy_stages' do
subject { pipeline.legacy_stages } subject { pipeline.legacy_stages }
...@@ -596,21 +587,6 @@ describe Ci::Pipeline, :mailer do ...@@ -596,21 +587,6 @@ describe Ci::Pipeline, :mailer do
end end
end end
describe '#has_stage_seeds?' do
context 'when pipeline has stage seeds' do
let(:project) { create(:project, :repository) }
subject { build(:ci_pipeline_with_one_job, project: project) }
it { is_expected.to have_stage_seeds }
end
context 'when pipeline does not have stage seeds' do
subject { create(:ci_pipeline_without_jobs) }
it { is_expected.not_to have_stage_seeds }
end
end
describe '#has_warnings?' do describe '#has_warnings?' do
subject { pipeline.has_warnings? } subject { pipeline.has_warnings? }
......
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