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.
#
2021-01-03 14:25:43 +05:30
class Jobs < ::Gitlab::Config::Entry::ComposableHash
2019-02-15 15:39:39 +05:30
include ::Gitlab::Config::Entry::Validatable
2016-09-13 17:45:13 +05:30
validations do
validates :config, type: Hash
validate do
2020-11-24 15:15:51 +05:30
each_unmatched_job do |name|
errors.add(name, 'config should implement a script: or a trigger: keyword')
2019-09-30 21:07:59 +05:30
end
2016-09-13 17:45:13 +05:30
unless has_visible_job?
errors.add(:config, 'should contain at least one visible job')
end
end
2020-11-24 15:15:51 +05:30
def each_unmatched_job
config.each do |name, value|
yield(name) unless Jobs.find_type(name, value)
2019-09-30 21:07:59 +05:30
end
end
2016-09-13 17:45:13 +05:30
def has_visible_job?
2019-09-30 21:07:59 +05:30
config.any? do |name, value|
Jobs.find_type(name, value)&.visible?
end
2016-09-13 17:45:13 +05:30
end
end
2021-01-03 14:25:43 +05:30
def composable_class(name, config)
self.class.find_type(name, config)
end
2020-03-13 15:44:24 +05:30
TYPES = [Entry::Hidden, Entry::Job, Entry::Bridge].freeze
2019-09-30 21:07:59 +05:30
private_constant :TYPES
def self.all_types
TYPES
2016-09-13 17:45:13 +05:30
end
2019-09-30 21:07:59 +05:30
def self.find_type(name, config)
self.all_types.find do |type|
type.matching?(name, config)
end
2019-03-02 22:35:43 +05:30
end
2016-09-13 17:45:13 +05:30
end
end
end
end
end