2019-11-08 07:06:32 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Entry
|
|
|
|
##
|
|
|
|
# Entry that represents a set of needs dependencies.
|
|
|
|
#
|
|
|
|
class Needs < ::Gitlab::Config::Entry::Node
|
|
|
|
include ::Gitlab::Config::Entry::Validatable
|
|
|
|
|
|
|
|
validations do
|
|
|
|
validate do
|
|
|
|
unless config.is_a?(Hash) || config.is_a?(Array)
|
|
|
|
errors.add(:config, 'can only be a Hash or an Array')
|
|
|
|
end
|
2020-02-14 07:09:03 -05:00
|
|
|
|
|
|
|
if config.is_a?(Hash) && config.empty?
|
|
|
|
errors.add(:config, 'can not be an empty Hash')
|
|
|
|
end
|
2019-11-08 07:06:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
validate on: :composed do
|
|
|
|
extra_keys = value.keys - opt(:allowed_needs)
|
|
|
|
if extra_keys.any?
|
|
|
|
errors.add(:config, "uses invalid types: #{extra_keys.join(', ')}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def compose!(deps = nil)
|
|
|
|
super(deps) do
|
|
|
|
[@config].flatten.each_with_index do |need, index|
|
|
|
|
@entries[index] = ::Gitlab::Config::Entry::Factory.new(Entry::Need)
|
|
|
|
.value(need)
|
|
|
|
.with(key: "need", parent: self, description: "need definition.") # rubocop:disable CodeReuse/ActiveRecord
|
|
|
|
.create!
|
|
|
|
end
|
|
|
|
|
|
|
|
@entries.each_value do |entry|
|
|
|
|
entry.compose!(deps)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
values = @entries.values.select(&:type)
|
|
|
|
values.group_by(&:type).transform_values do |values|
|
|
|
|
values.map(&:value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-17 19:08:09 -05:00
|
|
|
|
|
|
|
::Gitlab::Ci::Config::Entry::Needs.prepend_if_ee('::EE::Gitlab::Ci::Config::Entry::Needs')
|