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