debian-mirror-gitlab/lib/gitlab/ci/config/entry/rules/rule.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
2.1 KiB
Ruby
Raw Normal View History

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
2021-02-22 17:27:13 +05:30
include ::Gitlab::Config::Entry::Configurable
2019-12-04 20:38:33 +05:30
include ::Gitlab::Config::Entry::Attributable
2022-07-23 23:45:48 +05:30
ALLOWED_KEYS = %i[if changes exists when start_in allow_failure variables].freeze
ALLOWED_WHEN = %w[on_success on_failure always never manual delayed].freeze
2019-12-04 20:38:33 +05:30
2022-07-23 23:45:48 +05:30
attributes :if, :exists, :when, :start_in, :allow_failure
entry :changes, Entry::Rules::Rule::Changes,
description: 'File change condition rule.'
2019-12-04 20:38:33 +05:30
2021-02-22 17:27:13 +05:30
entry :variables, Entry::Variables,
description: 'Environment variables to define for rule conditions.'
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?
2022-05-07 20:08:51 +05:30
validates :start_in, duration: { limit: '1 week' }, if: :specifies_delay?
2019-12-04 20:38:33 +05:30
with_options allow_nil: true do
validates :if, expression: true
2022-07-23 23:45:48 +05:30
validates :exists, array_of_strings: true, length: { maximum: 50 }
validates :when, allowed_values: { in: ALLOWED_WHEN }
2020-03-13 15:44:24 +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
2022-07-23 23:45:48 +05:30
def value
config.merge(
changes: (changes_value if changes_defined?),
variables: (variables_value if variables_defined?)
).compact
end
2019-12-04 20:38:33 +05:30
def specifies_delay?
self.when == 'delayed'
end
def default
end
end
end
end
end
end