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

108 lines
3.8 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module Entry
##
2022-05-07 20:08:51 +05:30
# Entry that represents a parent-child or cross-project downstream trigger.
2020-03-13 15:44:24 +05:30
#
class Trigger < ::Gitlab::Config::Entry::Simplifiable
strategy :SimpleTrigger, if: -> (config) { config.is_a?(String) }
strategy :ComplexTrigger, if: -> (config) { config.is_a?(Hash) }
2022-05-07 20:08:51 +05:30
# cross-project
2020-03-13 15:44:24 +05:30
class SimpleTrigger < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
validations { validates :config, presence: true }
def value
{ project: @config }
end
end
class ComplexTrigger < ::Gitlab::Config::Entry::Simplifiable
strategy :CrossProjectTrigger, if: -> (config) { !config.key?(:include) }
strategy :SameProjectTrigger, if: -> (config) do
2020-05-24 23:13:21 +05:30
config.key?(:include)
2020-03-13 15:44:24 +05:30
end
2022-05-07 20:08:51 +05:30
# cross-project
2020-03-13 15:44:24 +05:30
class CrossProjectTrigger < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
2022-05-07 20:08:51 +05:30
include ::Gitlab::Config::Entry::Configurable
2020-03-13 15:44:24 +05:30
2022-05-07 20:08:51 +05:30
ALLOWED_KEYS = %i[project branch strategy forward].freeze
2020-03-13 15:44:24 +05:30
attributes :project, :branch, :strategy
validations do
validates :config, presence: true
validates :config, allowed_keys: ALLOWED_KEYS
validates :project, presence: true
validates :branch, type: String, allow_nil: true
validates :strategy, type: String, inclusion: { in: %w[depend], message: 'should be depend' }, allow_nil: true
end
2022-05-07 20:08:51 +05:30
entry :forward, ::Gitlab::Ci::Config::Entry::Trigger::Forward,
description: 'List what to forward to downstream pipelines'
def value
{ project: project,
branch: branch,
strategy: strategy,
forward: forward_value }.compact
end
2020-03-13 15:44:24 +05:30
end
2022-05-07 20:08:51 +05:30
# parent-child
2020-03-13 15:44:24 +05:30
class SameProjectTrigger < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable
INCLUDE_MAX_SIZE = 3
2022-05-07 20:08:51 +05:30
ALLOWED_KEYS = %i[strategy include forward].freeze
2020-03-13 15:44:24 +05:30
attributes :strategy
validations do
validates :config, presence: true
validates :config, allowed_keys: ALLOWED_KEYS
validates :strategy, type: String, inclusion: { in: %w[depend], message: 'should be depend' }, allow_nil: true
end
entry :include, ::Gitlab::Ci::Config::Entry::Includes,
description: 'List of external YAML files to include.',
reserved: true,
metadata: { max_size: INCLUDE_MAX_SIZE }
2022-05-07 20:08:51 +05:30
entry :forward, ::Gitlab::Ci::Config::Entry::Trigger::Forward,
description: 'List what to forward to downstream pipelines'
2020-03-13 15:44:24 +05:30
def value
2022-05-07 20:08:51 +05:30
{ include: @config[:include],
strategy: strategy,
forward: forward_value }.compact
2020-03-13 15:44:24 +05:30
end
end
class UnknownStrategy < ::Gitlab::Config::Entry::Node
def errors
2020-05-24 23:13:21 +05:30
['config must specify either project or include']
2020-03-13 15:44:24 +05:30
end
end
end
class UnknownStrategy < ::Gitlab::Config::Entry::Node
def errors
["#{location} has to be either a string or a hash"]
end
end
end
end
end
end
end