diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-18 12:37:42 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-18 12:37:42 +0200 |
commit | 1bf9e34713b414f0e1ac8bbfe464a4cd5300581f (patch) | |
tree | 7bb7b1165563ad2515d41369ececf96a83b05f73 | |
parent | 27e88efceb9d59affebf93be040b0a9b0bf31b2f (diff) | |
download | gitlab-ce-1bf9e34713b414f0e1ac8bbfe464a4cd5300581f.tar.gz |
Move except and only job nodes to new CI config
-rw-r--r-- | lib/gitlab/ci/config/node/job.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/while.rb | 26 | ||||
-rw-r--r-- | spec/lib/ci/gitlab_ci_yaml_processor_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/while_spec.rb | 56 |
4 files changed, 93 insertions, 3 deletions
diff --git a/lib/gitlab/ci/config/node/job.rb b/lib/gitlab/ci/config/node/job.rb index 1c28969be14..401611def17 100644 --- a/lib/gitlab/ci/config/node/job.rb +++ b/lib/gitlab/ci/config/node/job.rb @@ -38,8 +38,14 @@ module Gitlab node :services, Services, description: 'Services that will be used to execute this job.' + node :only, While, + description: 'Refs policy this job will be executed for.' + + node :except, While, + description: 'Refs policy this job will be executed for.' + helpers :before_script, :script, :stage, :type, :after_script, - :cache, :image, :services + :cache, :image, :services, :only, :except def name @metadata[:name] @@ -59,6 +65,8 @@ module Gitlab services: services, stage: stage, cache: cache, + only: only, + except: except, after_script: after_script } end diff --git a/lib/gitlab/ci/config/node/while.rb b/lib/gitlab/ci/config/node/while.rb new file mode 100644 index 00000000000..84d4352624d --- /dev/null +++ b/lib/gitlab/ci/config/node/while.rb @@ -0,0 +1,26 @@ +module Gitlab + module Ci + class Config + module Node + ## + # Entry that represents a ref and trigger policy for the job. + # + class While < Entry + include Validatable + + validations do + include LegacyValidationHelpers + + validate :array_of_strings_or_regexps + + def array_of_strings_or_regexps + unless validate_array_of_strings_or_regexps(config) + errors.add(:config, 'should be an array of strings or regexps') + end + end + end + end + end + end + end +end diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb index 6e6898e758c..429ffd6ef35 100644 --- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb @@ -163,7 +163,7 @@ module Ci shared_examples 'raises an error' do it do - expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'rspec job: only parameter should be an array of strings or regexps') + expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'jobs:rspec:only config should be an array of strings or regexps') end end @@ -319,7 +319,7 @@ module Ci shared_examples 'raises an error' do it do - expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'rspec job: except parameter should be an array of strings or regexps') + expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'jobs:rspec:except config should be an array of strings or regexps') end end diff --git a/spec/lib/gitlab/ci/config/node/while_spec.rb b/spec/lib/gitlab/ci/config/node/while_spec.rb new file mode 100644 index 00000000000..aac2ed7b3db --- /dev/null +++ b/spec/lib/gitlab/ci/config/node/while_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Node::While do + let(:entry) { described_class.new(config) } + + describe 'validations' do + context 'when entry config value is valid' do + context 'when config is a branch or tag name' do + let(:config) { %w[master feature/branch] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#value' do + it 'returns key value' do + expect(entry.value).to eq config + end + end + end + + context 'when config is a regexp' do + let(:config) { ['/^issue-.*$/'] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when config is a special keyword' do + let(:config) { %w[tags triggers branches] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + end + + context 'when entry value is not valid' do + let(:config) { [1] } + + describe '#errors' do + it 'saves errors' do + expect(entry.errors) + .to include 'while config should be an array of strings or regexps' + end + end + end + end +end |