2020-03-09 13:42:32 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Entry
|
|
|
|
##
|
|
|
|
# Entry that represents a CI/CD Bridge job that is responsible for
|
|
|
|
# defining a downstream project trigger.
|
|
|
|
#
|
|
|
|
class Bridge < ::Gitlab::Config::Entry::Node
|
2020-04-08 14:13:33 +05:30
|
|
|
include ::Gitlab::Ci::Config::Entry::Processable
|
2020-03-09 13:42:32 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
ALLOWED_KEYS = %i[trigger allow_failure when needs].freeze
|
2020-03-09 13:42:32 +05:30
|
|
|
|
|
|
|
validations do
|
2020-04-08 14:13:33 +05:30
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS + PROCESSABLE_ALLOWED_KEYS
|
2020-03-09 13:42:32 +05:30
|
|
|
|
|
|
|
with_options allow_nil: true do
|
|
|
|
validates :when,
|
|
|
|
inclusion: { in: %w[on_success on_failure always],
|
|
|
|
message: 'should be on_success, on_failure or always' }
|
|
|
|
end
|
|
|
|
|
|
|
|
validate on: :composed do
|
2020-04-08 14:13:33 +05:30
|
|
|
unless trigger_defined? || bridge_needs.present?
|
2020-03-09 13:42:32 +05:30
|
|
|
errors.add(:config, 'should contain either a trigger or a needs:pipeline')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
validate on: :composed do
|
|
|
|
next unless bridge_needs.present?
|
|
|
|
next if bridge_needs.one?
|
|
|
|
|
|
|
|
errors.add(:config, 'should contain at most one bridge need')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
entry :trigger, ::Gitlab::Ci::Config::Entry::Trigger,
|
|
|
|
description: 'CI/CD Bridge downstream trigger definition.',
|
|
|
|
inherit: false
|
|
|
|
|
|
|
|
entry :needs, ::Gitlab::Ci::Config::Entry::Needs,
|
|
|
|
description: 'CI/CD Bridge needs dependency definition.',
|
|
|
|
inherit: false,
|
|
|
|
metadata: { allowed_needs: %i[job bridge] }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
attributes :when, :allow_failure
|
2020-03-09 13:42:32 +05:30
|
|
|
|
|
|
|
def self.matching?(name, config)
|
|
|
|
!name.to_s.start_with?('.') &&
|
|
|
|
config.is_a?(Hash) &&
|
|
|
|
(config.key?(:trigger) || config.key?(:needs))
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.visible?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
2020-04-08 14:13:33 +05:30
|
|
|
super.merge(
|
2020-03-09 13:42:32 +05:30
|
|
|
trigger: (trigger_value if trigger_defined?),
|
|
|
|
needs: (needs_value if needs_defined?),
|
|
|
|
ignore: !!allow_failure,
|
2020-04-08 14:13:33 +05:30
|
|
|
when: self.when,
|
|
|
|
scheduling_type: needs_defined? && !bridge_needs ? :dag : :stage
|
|
|
|
).compact
|
2020-03-09 13:42:32 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def bridge_needs
|
|
|
|
needs_value[:bridge] if needs_value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|