Commit 4bb60b07 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Simplify CI config and remove logical validation

parent 41bcbdd8
......@@ -15,7 +15,6 @@ module Gitlab
@global = Node::Global.new(@config)
@global.process!
@global.validate!
end
def valid?
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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' } } }
......
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