2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
2017-08-17 22:00:37 +05:30
|
|
|
module Entry
|
2016-09-13 17:45:13 +05:30
|
|
|
##
|
|
|
|
# Entry that represents a set of jobs.
|
|
|
|
#
|
2019-01-03 12:48:30 +05:30
|
|
|
class Jobs < Node
|
|
|
|
include Validatable
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config, type: Hash
|
|
|
|
|
|
|
|
validate do
|
|
|
|
unless has_visible_job?
|
|
|
|
errors.add(:config, 'should contain at least one visible job')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_visible_job?
|
|
|
|
config.any? { |name, _| !hidden?(name) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def hidden?(name)
|
|
|
|
name.to_s.start_with?('.')
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-09-29 09:46:39 +05:30
|
|
|
def compose!(deps = nil)
|
|
|
|
super do
|
|
|
|
@config.each do |name, config|
|
2017-08-17 22:00:37 +05:30
|
|
|
node = hidden?(name) ? Entry::Hidden : Entry::Job
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2019-01-03 12:48:30 +05:30
|
|
|
factory = Entry::Factory.new(node)
|
2016-09-29 09:46:39 +05:30
|
|
|
.value(config || {})
|
|
|
|
.metadata(name: name)
|
|
|
|
.with(key: name, parent: self,
|
|
|
|
description: "#{name} job definition.")
|
|
|
|
|
|
|
|
@entries[name] = factory.create!
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
@entries.each_value do |entry|
|
|
|
|
entry.compose!(deps)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|