1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module Entry
##
# Entry that represents a set of jobs.
#
class Jobs < ::Gitlab::Config::Entry::ComposableHash
include ::Gitlab::Config::Entry::Validatable
validations do
validates :config, type: Hash
validate do
each_unmatched_job do |name|
errors.add(name, 'config should implement a script: or a trigger: keyword')
end
unless has_visible_job?
errors.add(:config, 'should contain at least one visible job')
end
end
def each_unmatched_job
config.each do |name, value|
yield(name) unless Jobs.find_type(name, value)
end
end
def has_visible_job?
config.any? do |name, value|
Jobs.find_type(name, value)&.visible?
end
end
end
def composable_class(name, config)
self.class.find_type(name, config)
end
TYPES = [Entry::Hidden, Entry::Job, Entry::Bridge].freeze
private_constant :TYPES
def self.all_types
TYPES
end
def self.find_type(name, config)
self.all_types.find do |type|
type.matching?(name, config)
end
end
end
end
end
end
end
|