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

112 lines
3.2 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
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,
2021-02-22 17:27:13 +05:30
if: -> (config) { config.is_a?(Hash) && same_pipeline_need?(config) }
strategy :CrossPipelineDependency,
if: -> (config) { config.is_a?(Hash) && cross_pipeline_need?(config) }
def self.same_pipeline_need?(config)
config.key?(:job) &&
!(config.key?(:project) || config.key?(:ref) || config.key?(:pipeline))
end
def self.cross_pipeline_need?(config)
config.key?(:job) && config.key?(:pipeline) && !config.key?(:project)
end
2020-01-01 13:55:28 +05:30
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
2021-09-04 01:27:46 +05:30
{ name: @config,
artifacts: true,
optional: false }
2020-01-01 13:55:28 +05:30
end
end
class JobHash < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
2021-04-17 20:07:23 +05:30
ALLOWED_KEYS = %i[job artifacts optional].freeze
attributes :job, :artifacts, :optional
2020-01-01 13:55:28 +05:30
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
2021-04-17 20:07:23 +05:30
validates :optional, boolean: true, allow_nil: true
2020-01-01 13:55:28 +05:30
end
def type
:job
end
def value
2021-09-04 01:27:46 +05:30
{ name: job,
artifacts: artifacts || artifacts.nil?,
optional: !!optional }
2019-12-26 22:10:19 +05:30
end
end
2021-02-22 17:27:13 +05:30
class CrossPipelineDependency < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
ALLOWED_KEYS = %i[pipeline job artifacts].freeze
attributes :pipeline, :job, :artifacts
validations do
validates :config, presence: true
validates :config, allowed_keys: ALLOWED_KEYS
validates :pipeline, type: String, presence: true
validates :job, type: String, presence: true
validates :artifacts, boolean: true, allow_nil: true
end
def type
:cross_dependency
end
def value
super.merge(artifacts: artifacts || artifacts.nil?)
end
end
2019-12-26 22:10:19 +05:30
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
2021-06-08 01:23:25 +05:30
::Gitlab::Ci::Config::Entry::Need.prepend_mod_with('Gitlab::Ci::Config::Entry::Need')