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

67 lines
2.5 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Gitlab
module Ci
class Config
2017-08-17 22:00:37 +05:30
module Entry
2016-09-13 17:45:13 +05:30
##
# Entry that represents a configuration of job artifacts.
#
2019-02-15 15:39:39 +05:30
class Artifacts < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Configurable
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
2016-09-13 17:45:13 +05:30
2021-03-08 18:12:59 +05:30
ALLOWED_KEYS = %i[name untracked paths reports when expire_in expose_as exclude public].freeze
2019-12-26 22:10:19 +05:30
EXPOSE_AS_REGEX = /\A\w[-\w ]*\z/.freeze
EXPOSE_AS_ERROR_MESSAGE = "can contain only letters, digits, '-', '_' and spaces"
2016-09-13 17:45:13 +05:30
attributes ALLOWED_KEYS
2018-11-18 11:00:15 +05:30
entry :reports, Entry::Reports, description: 'Report-type artifacts.'
2016-09-13 17:45:13 +05:30
validations do
validates :config, type: Hash
validates :config, allowed_keys: ALLOWED_KEYS
2019-12-26 22:10:19 +05:30
validates :paths, presence: true, if: :expose_as_present?
2016-09-13 17:45:13 +05:30
with_options allow_nil: true do
validates :name, type: String
2021-03-08 18:12:59 +05:30
validates :public, boolean: true
2016-09-13 17:45:13 +05:30
validates :untracked, boolean: true
validates :paths, array_of_strings: true
2019-12-26 22:10:19 +05:30
validates :paths, array_of_strings: {
with: /\A[^*]*\z/,
message: "can't contain '*' when used with 'expose_as'"
}, if: :expose_as_present?
validates :expose_as, type: String, length: { maximum: 100 }, if: :expose_as_present?
validates :expose_as, format: { with: EXPOSE_AS_REGEX, message: EXPOSE_AS_ERROR_MESSAGE }, if: :expose_as_present?
2021-09-30 23:02:18 +05:30
validates :exclude, array_of_strings: true
2018-11-18 11:00:15 +05:30
validates :reports, type: Hash
2016-09-13 17:45:13 +05:30
validates :when,
inclusion: { in: %w[on_success on_failure always],
message: 'should be on_success, on_failure ' \
'or always' }
2020-10-24 23:57:45 +05:30
validates :expire_in, duration: { parser: ::Gitlab::Ci::Build::Artifacts::ExpireInParser }
2016-09-13 17:45:13 +05:30
end
end
2018-11-18 11:00:15 +05:30
def value
@config[:reports] = reports_value if @config.key?(:reports)
@config
end
2019-12-26 22:10:19 +05:30
def expose_as_present?
2020-01-12 00:16:45 +05:30
# This duplicates the `validates :config, type: Hash` above,
# but Validatable currently doesn't halt the validation
# chain if it encounters a validation error.
return false unless @config.is_a?(Hash)
2019-12-26 22:10:19 +05:30
!@config[:expose_as].nil?
end
2016-09-13 17:45:13 +05:30
end
end
end
end
end