2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Entry
|
|
|
|
class Need < ::Gitlab::Config::Entry::Simplifiable
|
2020-01-01 13:55:28 +05:30
|
|
|
strategy :JobString, if: -> (config) { config.is_a?(String) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
strategy :JobHash,
|
|
|
|
if: -> (config) { config.is_a?(Hash) && config.key?(:job) && !(config.key?(:project) || config.key?(:ref)) }
|
|
|
|
|
|
|
|
class JobString < ::Gitlab::Config::Entry::Node
|
2019-12-26 22:10:19 +05:30
|
|
|
include ::Gitlab::Config::Entry::Validatable
|
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config, presence: true
|
|
|
|
validates :config, type: String
|
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
:job
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
2020-01-01 13:55:28 +05:30
|
|
|
{ name: @config, artifacts: true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class JobHash < ::Gitlab::Config::Entry::Node
|
|
|
|
include ::Gitlab::Config::Entry::Validatable
|
|
|
|
include ::Gitlab::Config::Entry::Attributable
|
|
|
|
|
|
|
|
ALLOWED_KEYS = %i[job artifacts].freeze
|
|
|
|
attributes :job, :artifacts
|
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config, presence: true
|
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS
|
|
|
|
validates :job, type: String, presence: true
|
|
|
|
validates :artifacts, boolean: true, allow_nil: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
:job
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
{ name: job, artifacts: artifacts || artifacts.nil? }
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class UnknownStrategy < ::Gitlab::Config::Entry::Node
|
|
|
|
def type
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
|
|
|
["#{location} has an unsupported type"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
::Gitlab::Ci::Config::Entry::Need.prepend_if_ee('::EE::Gitlab::Ci::Config::Entry::Need')
|