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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.8 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
2021-02-22 17:27:13 +05:30
NEEDS_CROSS_PIPELINE_DEPENDENCIES_LIMIT = 5
2019-12-26 22:10:19 +05:30
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
2021-02-22 17:27:13 +05:30
validate on: :composed do
cross_dependencies = value[:cross_dependency].to_a
cross_pipeline_dependencies = cross_dependencies.select { |dep| dep[:pipeline] }
if cross_pipeline_dependencies.size > NEEDS_CROSS_PIPELINE_DEPENDENCIES_LIMIT
errors.add(:config, "must be less than or equal to #{NEEDS_CROSS_PIPELINE_DEPENDENCIES_LIMIT}")
end
end
2019-12-26 22:10:19 +05:30
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
2021-06-08 01:23:25 +05:30
::Gitlab::Ci::Config::Entry::Needs.prepend_mod_with('Gitlab::Ci::Config::Entry::Needs')