2022-07-23 23:45:48 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Entry
|
|
|
|
class Rules
|
|
|
|
class Rule
|
2022-08-13 15:12:31 +05:30
|
|
|
class Changes < ::Gitlab::Config::Entry::Simplifiable
|
|
|
|
strategy :SimpleChanges, if: -> (config) { config.is_a?(Array) }
|
|
|
|
strategy :ComplexChanges, if: -> (config) { config.is_a?(Hash) }
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
class SimpleChanges < ::Gitlab::Config::Entry::Node
|
|
|
|
include ::Gitlab::Config::Entry::Validatable
|
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config,
|
|
|
|
array_of_strings: true,
|
|
|
|
length: { maximum: 50, too_long: "has too many entries (maximum %{count})" }
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
{
|
|
|
|
paths: config
|
|
|
|
}.compact
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ComplexChanges < ::Gitlab::Config::Entry::Node
|
|
|
|
include ::Gitlab::Config::Entry::Validatable
|
|
|
|
include ::Gitlab::Config::Entry::Attributable
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
ALLOWED_KEYS = %i[paths compare_to].freeze
|
2022-08-13 15:12:31 +05:30
|
|
|
REQUIRED_KEYS = %i[paths].freeze
|
|
|
|
|
|
|
|
attributes ALLOWED_KEYS
|
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS
|
|
|
|
validates :config, required_keys: REQUIRED_KEYS
|
|
|
|
|
|
|
|
with_options allow_nil: false do
|
|
|
|
validates :paths,
|
|
|
|
array_of_strings: true,
|
|
|
|
length: { maximum: 50, too_long: "has too many entries (maximum %{count})" }
|
2022-08-27 11:52:29 +05:30
|
|
|
validates :compare_to, type: String, allow_nil: true
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class UnknownStrategy < ::Gitlab::Config::Entry::Node
|
|
|
|
def errors
|
|
|
|
["#{location} should be an array or a hash"]
|
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|