Implement CI/CD config attributes for persisted stages
This commit is contained in:
parent
ff61e2b776
commit
1f1f570724
3 changed files with 53 additions and 4 deletions
|
@ -50,10 +50,20 @@ module Ci
|
|||
end
|
||||
end
|
||||
|
||||
def stages_for_ref(ref, tag = false, trigger_request = nil)
|
||||
stages = @stages.map do |stage|
|
||||
builds = builds_for_stage_and_ref(stage, ref, tag, trigger_request)
|
||||
|
||||
{ name: stage, builds_attributes: builds.to_a } if builds.any?
|
||||
end
|
||||
|
||||
stages.compact.sort_by { |stage| @stages.index(stage[:name]) }
|
||||
end
|
||||
|
||||
def build_attributes(name)
|
||||
job = @jobs[name.to_sym] || {}
|
||||
{
|
||||
stage_idx: @stages.index(job[:stage]),
|
||||
|
||||
{ stage_idx: @stages.index(job[:stage]),
|
||||
stage: job[:stage],
|
||||
commands: job[:commands],
|
||||
tag_list: job[:tags] || [],
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
module Ci
|
||||
describe GitlabCiYamlProcessor, lib: true do
|
||||
describe GitlabCiYamlProcessor, :lib do
|
||||
subject { described_class.new(config, path) }
|
||||
let(:path) { 'path' }
|
||||
|
||||
describe 'our current .gitlab-ci.yml' do
|
||||
|
@ -82,6 +83,44 @@ module Ci
|
|||
end
|
||||
end
|
||||
|
||||
describe '#stages_for_ref' do
|
||||
context 'when no refs policy is specified' do
|
||||
let(:config) do
|
||||
YAML.dump(production: { stage: 'deploy', script: 'cap prod' },
|
||||
rspec: { stage: 'test', script: 'rspec' },
|
||||
spinach: { stage: 'test', script: 'spinach' })
|
||||
end
|
||||
|
||||
it 'returns model attributes for stages with nested jobs' do
|
||||
attributes = subject.stages_for_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'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when refs policy is specified' do
|
||||
let(:config) do
|
||||
YAML.dump(production: { stage: 'deploy', script: 'cap prod', only: ['master'] },
|
||||
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)
|
||||
|
||||
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'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#builds_for_ref" do
|
||||
let(:type) { 'test' }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Ci::CreatePipelineService, services: true do
|
||||
describe Ci::CreatePipelineService, :services do
|
||||
let(:project) { create(:project, :repository) }
|
||||
let(:user) { create(:admin) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue