BigW Consortium Gitlab

Commit c72e21fd by Grzegorz Bizon

Return stage seeds object from YAML processor

parent c881425b
......@@ -295,14 +295,16 @@ module Ci
sort_by { |build| build[:stage_idx] }
end
def config_stages_attributes
def stage_seeds
return [] unless config_processor
config_processor.stages_for_ref(ref, tag?, trigger_requests.first)
config_processor.stage_seeds(ref: ref,
tag: tag?,
trigger: trigger_requests.first)
end
def has_stages?
config_stages_attributes.any?
stage_seeds.has_stages?
end
def has_warnings?
......
......@@ -50,14 +50,14 @@ module Ci
end
end
def stages_for_ref(ref, tag = false, trigger_request = nil)
stages = @stages.uniq.map do |stage|
builds = builds_for_stage_and_ref(stage, ref, tag, trigger_request)
def stage_seeds(ref:, tag: false, trigger: nil)
Gitlab::Ci::Stage::Seeds.new.tap do |seeds|
@stages.uniq.each do |stage|
builds = builds_for_stage_and_ref(stage, ref, tag, trigger)
{ name: stage, builds_attributes: builds.to_a } if builds.any?
seeds.append_stage(stage, builds) if builds.any?
end
end
stages.compact.sort_by { |stage| @stages.index(stage[:name]) }
end
def build_attributes(name)
......
......@@ -8,6 +8,10 @@ module Gitlab
@stages = []
end
def has_stages?
@stages.any?
end
def stages
@stages.map(&:stage)
end
......@@ -48,7 +52,7 @@ module Gitlab
end
def to_attributes
@stages.map.with_index do |seed|
@stages.map do |seed|
seed.stage.merge(builds_attributes: seed.jobs)
end
end
......
......@@ -83,7 +83,7 @@ module Ci
end
end
describe '#stages_for_ref' do
describe '#stage_seeds' do
context 'when no refs policy is specified' do
let(:config) do
YAML.dump(production: { stage: 'deploy', script: 'cap prod' },
......@@ -91,15 +91,15 @@ module Ci
spinach: { stage: 'test', script: 'spinach' })
end
it 'returns model attributes for stages with nested jobs' do
attributes = subject.stages_for_ref('master')
it 'returns correctly fabricated stage seeds object' do
seeds = subject.stage_seeds(ref: 'master')
expect(attributes.size).to eq 2
expect(attributes.dig(0, :name)).to eq 'test'
expect(attributes.dig(1, :name)).to eq 'deploy'
expect(attributes.dig(0, :builds_attributes, 0, :name)).to eq 'rspec'
expect(attributes.dig(0, :builds_attributes, 1, :name)).to eq 'spinach'
expect(attributes.dig(1, :builds_attributes, 0, :name)).to eq 'production'
expect(seeds.stages.size).to eq 2
expect(seeds.stages.dig(0, :name)).to eq 'test'
expect(seeds.stages.dig(1, :name)).to eq 'deploy'
expect(seeds.jobs.dig(0, :name)).to eq 'rspec'
expect(seeds.jobs.dig(1, :name)).to eq 'spinach'
expect(seeds.jobs.dig(2, :name)).to eq 'production'
end
end
......@@ -109,14 +109,12 @@ module Ci
spinach: { stage: 'test', script: 'spinach', only: ['tags'] })
end
it 'returns stage attributes except of jobs assigned to master' do
# true flag argument means matching jobs for tags
#
attributes = subject.stages_for_ref('feature', true)
it 'returns stage seeds only assigned to master to master' do
seeds = subject.stage_seeds(ref: 'feature', tag: true)
expect(attributes.size).to eq 1
expect(attributes.dig(0, :name)).to eq 'test'
expect(attributes.dig(0, :builds_attributes, 0, :name)).to eq 'spinach'
expect(seeds.stages.size).to eq 1
expect(seeds.stages.dig(0, :name)).to eq 'test'
expect(seeds.jobs.dig(0, :name)).to eq 'spinach'
end
end
end
......
......@@ -6,6 +6,10 @@ describe Gitlab::Ci::Stage::Seeds do
subject.append_stage('deploy', [{ name: 'prod', script: 'cap deploy' }])
end
describe '#has_stages?' do
it { is_expected.to have_stages }
end
describe '#stages' do
it 'returns hashes of all stages' do
expect(subject.stages.size).to eq 2
......
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