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

49 lines
1.3 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module Entry
##
# Entry that represents a set of needs dependencies.
#
2021-01-03 14:25:43 +05:30
class Needs < ::Gitlab::Config::Entry::ComposableArray
2019-12-26 22:10:19 +05:30
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-03-13 15:44:24 +05:30
if config.is_a?(Hash) && config.empty?
errors.add(:config, 'can not be an empty Hash')
end
2019-12-26 22:10:19 +05:30
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 value
2021-01-03 14:25:43 +05:30
values = @entries.select(&:type)
2019-12-26 22:10:19 +05:30
values.group_by(&:type).transform_values do |values|
values.map(&:value)
end
end
2021-01-03 14:25:43 +05:30
def composable_class
Entry::Need
end
2019-12-26 22:10:19 +05:30
end
end
end
end
end
2020-01-01 13:55:28 +05:30
::Gitlab::Ci::Config::Entry::Needs.prepend_if_ee('::EE::Gitlab::Ci::Config::Entry::Needs')