diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-30 12:48:05 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-05-30 12:48:05 +0200 |
commit | 1f1f5707244bcf4e69ef0fbe01f93e59386d5087 (patch) | |
tree | 4dac972bc05a830bdf06bc6412bab085111c6fdc | |
parent | ff61e2b776badef7cd614e697a7eac20c63534eb (diff) | |
download | gitlab-ce-1f1f5707244bcf4e69ef0fbe01f93e59386d5087.tar.gz |
Implement CI/CD config attributes for persisted stages
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 14 | ||||
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 41 | ||||
-rw-r--r-- | spec/services/ci/create_pipeline_service_spec.rb | 2 |
3 files changed, 53 insertions, 4 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index b06474cda7f..17a3cdc714c 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -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] || [], diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index fe2c00bb2ca..f98da1916b4 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -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' } diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index b536103ed65..674de2d80c1 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -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) } |