Commit f83bccfe authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add minor readability, style improvements in CI config

parent 795c9f22
......@@ -8,7 +8,8 @@ module Ci
def initialize(config, path = nil)
@ci_config = Gitlab::Ci::Config.new(config)
@config, @path = @ci_config.to_hash, path
@config = @ci_config.to_hash
@path = path
unless @ci_config.valid?
raise ValidationError, @ci_config.errors.first
......@@ -120,8 +121,6 @@ module Ci
end
def validate_job!(name, job)
raise ValidationError, "Unknown parameter: #{name}" unless job.is_a?(Hash) && job.has_key?(:script)
validate_job_stage!(name, job) if job[:stage]
validate_job_dependencies!(name, job) if job[:dependencies]
end
......
......@@ -9,12 +9,13 @@ module Gitlab
include Validatable
include Attributable
attributes :name, :untracked, :paths, :when, :expire_in
ALLOWED_KEYS = %i[name untracked paths when expire_in]
attributes ALLOWED_KEYS
validations do
validates :config, type: Hash
validates :config,
allowed_keys: %i[name untracked paths when expire_in]
validates :config, allowed_keys: ALLOWED_KEYS
with_options allow_nil: true do
validates :name, type: String
......
......@@ -7,7 +7,7 @@ module Gitlab
class_methods do
def attributes(*attributes)
attributes.each do |attribute|
attributes.flatten.each do |attribute|
define_method(attribute) do
return unless config.is_a?(Hash)
......
......@@ -24,7 +24,7 @@ module Gitlab
return unless valid?
compose!
@entries.each_value(&:process!)
descendants.each(&:process!)
end
def leaf?
......@@ -44,7 +44,7 @@ module Gitlab
end
def errors
@validator.messages + @entries.values.flat_map(&:errors)
@validator.messages + descendants.flat_map(&:errors)
end
def value
......
......@@ -9,13 +9,14 @@ module Gitlab
include Configurable
include Attributable
ALLOWED_KEYS = %i[tags script only except type image services allow_failure
type stage when artifacts cache dependencies before_script
after_script variables environment]
attributes :tags, :allow_failure, :when, :environment
validations do
validates :config, allowed_keys:
%i[tags script only except type image services allow_failure
type stage when artifacts cache dependencies before_script
after_script variables environment]
validates :config, allowed_keys: ALLOWED_KEYS
validates :config, presence: true
validates :name, presence: true
......
......@@ -18,10 +18,14 @@ module Gitlab
end
def has_visible_job?
config.any? { |key, _| !key.to_s.start_with?('.') }
config.any? { |name, _| !hidden?(name) }
end
end
def hidden?(name)
name.to_s.start_with?('.')
end
private
def compose!
......@@ -37,10 +41,6 @@ module Gitlab
@entries[name] = factory.create!
end
end
def hidden?(name)
name.to_s.start_with?('.')
end
end
end
end
......
......@@ -5,7 +5,7 @@ module Gitlab
##
# This class represents an undefined and unspecified entry node.
#
# It decorates original entry adding method that idicates it is
# It decorates original entry adding method that indicates it is
# unspecified.
#
class Undefined < SimpleDelegator
......
......@@ -31,7 +31,7 @@ describe Gitlab::Ci::Config::Node::Artifacts do
end
end
context 'when there is uknown key' do
context 'when there is an unknown key present' do
let(:config) { { test: 100 } }
it 'reports error' do
......
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