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

89 lines
2.6 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
##
# 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-13 15:44:24 +05:30
2021-01-03 14:25:43 +05:30
ALLOWED_WHEN = %w[on_success on_failure always manual].freeze
2020-10-24 23:57:45 +05:30
ALLOWED_KEYS = %i[trigger].freeze
2020-03-13 15:44:24 +05:30
validations do
2020-04-08 14:13:33 +05:30
validates :config, allowed_keys: ALLOWED_KEYS + PROCESSABLE_ALLOWED_KEYS
2020-03-13 15:44:24 +05:30
with_options allow_nil: true do
2021-01-03 14:25:43 +05:30
validates :allow_failure, boolean: true
validates :when, inclusion: {
in: ALLOWED_WHEN,
message: "should be one of: #{ALLOWED_WHEN.join(', ')}"
}
2020-03-13 15:44:24 +05:30
end
validate on: :composed do
2020-04-08 14:13:33 +05:30
unless trigger_defined? || bridge_needs.present?
2020-03-13 15:44:24 +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-13 15:44:24 +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
2021-01-03 14:25:43 +05:30
def manual_action?
self.when == 'manual'
end
def ignored?
allow_failure.nil? ? manual_action? : allow_failure
end
2020-03-13 15:44:24 +05:30
def value
2020-04-08 14:13:33 +05:30
super.merge(
2020-03-13 15:44:24 +05:30
trigger: (trigger_value if trigger_defined?),
needs: (needs_value if needs_defined?),
2021-01-03 14:25:43 +05:30
ignore: ignored?,
2020-04-08 14:13:33 +05:30
when: self.when,
scheduling_type: needs_defined? && !bridge_needs ? :dag : :stage
).compact
2020-03-13 15:44:24 +05:30
end
def bridge_needs
needs_value[:bridge] if needs_value
end
end
end
end
end
end