2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Entry
|
|
|
|
class Rules::Rule < ::Gitlab::Config::Entry::Node
|
|
|
|
include ::Gitlab::Config::Entry::Validatable
|
|
|
|
include ::Gitlab::Config::Entry::Attributable
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
CLAUSES = %i[if changes exists].freeze
|
2020-03-09 13:42:32 +05:30
|
|
|
ALLOWED_KEYS = %i[if changes exists when start_in allow_failure].freeze
|
2019-12-26 22:10:19 +05:30
|
|
|
ALLOWABLE_WHEN = %w[on_success on_failure always never manual delayed].freeze
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
attributes :if, :changes, :exists, :when, :start_in, :allow_failure
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config, presence: true
|
|
|
|
validates :config, type: { with: Hash }
|
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS
|
|
|
|
validates :config, disallowed_keys: %i[start_in], unless: :specifies_delay?
|
|
|
|
validates :start_in, presence: true, if: :specifies_delay?
|
|
|
|
validates :start_in, duration: { limit: '1 day' }, if: :specifies_delay?
|
|
|
|
|
|
|
|
with_options allow_nil: true do
|
|
|
|
validates :if, expression: true
|
2019-12-21 20:55:43 +05:30
|
|
|
validates :changes, :exists, array_of_strings: true, length: { maximum: 50 }
|
2019-12-26 22:10:19 +05:30
|
|
|
validates :when, allowed_values: { in: ALLOWABLE_WHEN }
|
2020-03-09 13:42:32 +05:30
|
|
|
validates :allow_failure, boolean: true
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
validate do
|
|
|
|
validates_with Gitlab::Config::Entry::Validators::AllowedValuesValidator,
|
|
|
|
attributes: %i[when],
|
|
|
|
allow_nil: true,
|
|
|
|
in: opt(:allowed_when)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def specifies_delay?
|
|
|
|
self.when == 'delayed'
|
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|