BigW Consortium Gitlab

Commit 1f1f5707 by Grzegorz Bizon

Implement CI/CD config attributes for persisted stages

parent ff61e2b7
......@@ -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] || [],
......
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' }
......
require 'spec_helper'
describe Ci::CreatePipelineService, services: true do
describe Ci::CreatePipelineService, :services do
let(:project) { create(:project, :repository) }
let(:user) { create(:admin) }
......
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