diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-15 21:39:26 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-15 21:39:26 +0200 |
commit | 4bb60b0789a31061cbc81af90b7d5dc558f985b3 (patch) | |
tree | f4e68e77f5dcf63b367f9558c927c7ebbf958551 | |
parent | 41bcbdd8c2412769a376cd37541ad6e65a1af1f2 (diff) | |
download | gitlab-ce-4bb60b0789a31061cbc81af90b7d5dc558f985b3.tar.gz |
Simplify CI config and remove logical validation
-rw-r--r-- | lib/gitlab/ci/config.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/entry.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/global.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/jobs.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/job_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/jobs_spec.rb | 5 |
6 files changed, 12 insertions, 37 deletions
diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb index 20f5f8e2ff8..ae82c0db3f1 100644 --- a/lib/gitlab/ci/config.rb +++ b/lib/gitlab/ci/config.rb @@ -15,7 +15,6 @@ module Gitlab @global = Node::Global.new(@config) @global.process! - @global.validate! end def valid? diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb index 011c3be849e..559688c1bca 100644 --- a/lib/gitlab/ci/config/node/entry.rb +++ b/lib/gitlab/ci/config/node/entry.rb @@ -8,13 +8,13 @@ module Gitlab class Entry class InvalidError < StandardError; end - attr_reader :config, :attributes + attr_reader :config, :metadata attr_accessor :key, :parent, :description def initialize(config, **metadata) @config = config - @entries = {} @metadata = metadata + @entries = {} @validator = self.class.validator.new(self) @validator.validate(:new) @@ -27,13 +27,6 @@ module Gitlab @entries.each_value(&:process!) end - def validate! - return unless valid? - - @validator.validate(:processed) - @entries.each_value(&:validate!) - end - def leaf? nodes.none? end diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb index bedacd904cc..3b0d0113d61 100644 --- a/lib/gitlab/ci/config/node/global.rb +++ b/lib/gitlab/ci/config/node/global.rb @@ -36,19 +36,13 @@ module Gitlab helpers :before_script, :image, :services, :after_script, :variables, :stages, :types, :cache, :jobs - def initialize(*) - super - - @global = self - end - private def compose! super - compose_stages! compose_jobs! + compose_stages! end def compose_jobs! @@ -65,9 +59,6 @@ module Gitlab # Deprecated `:types` key workaround - if types are defined and # stages are not defined we use types definition as stages. # - # Otherwise we use stages in favor of types, and remove types from - # processing. - # if types_defined? && !stages_defined? @entries[:stages] = @entries[:types] end diff --git a/lib/gitlab/ci/config/node/jobs.rb b/lib/gitlab/ci/config/node/jobs.rb index 3cabcd6b763..77ff3459958 100644 --- a/lib/gitlab/ci/config/node/jobs.rb +++ b/lib/gitlab/ci/config/node/jobs.rb @@ -11,23 +11,21 @@ module Gitlab validations do validates :config, type: Hash - with_options on: :processed do - validate do - unless has_visible_job? - errors.add(:config, 'should contain at least one visible job') - end + validate do + unless has_visible_job? + errors.add(:config, 'should contain at least one visible job') end end + + def has_visible_job? + config.any? { |key, _| !key.to_s.start_with?('.') } + end end def nodes @config end - def has_visible_job? - @entries.values.any?(&:relevant?) - end - private def create(name, config) diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/node/job_spec.rb index b2559e6e73c..2721908c5d7 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/node/job_spec.rb @@ -3,10 +3,7 @@ require 'spec_helper' describe Gitlab::Ci::Config::Node::Job do let(:entry) { described_class.new(config, name: :rspec) } - before do - entry.process! - entry.validate! - end + before { entry.process! } describe 'validations' do context 'when entry config value is correct' do diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/node/jobs_spec.rb index 4f08f2f9b69..b8d9c70479c 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/node/jobs_spec.rb @@ -4,10 +4,7 @@ describe Gitlab::Ci::Config::Node::Jobs do let(:entry) { described_class.new(config) } describe 'validations' do - before do - entry.process! - entry.validate! - end + before { entry.process! } context 'when entry config value is correct' do let(:config) { { rspec: { script: 'rspec' } } } |