debian-mirror-gitlab/lib/gitlab/ci/config/entry/jobs.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

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-02-15 15:39:39 +05:30
class Jobs < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::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
2019-03-02 22:35:43 +05:30
def node_type(name)
hidden?(name) ? Entry::Hidden : Entry::Job
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|
2019-03-02 22:35:43 +05:30
node = node_type(name)
2016-09-29 09:46:39 +05:30
2019-02-15 15:39:39 +05:30
factory = ::Gitlab::Config::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