debian-mirror-gitlab/lib/gitlab/ci/config/external/mapper/matcher.rb

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

64 lines
1.9 KiB
Ruby
Raw Normal View History

2023-03-04 22:38:38 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module External
class Mapper
# Matches the first file type that matches the given location
class Matcher < Base
2023-06-20 00:43:36 +05:30
include Gitlab::Utils::StrongMemoize
2023-03-04 22:38:38 +05:30
private
def process_without_instrumentation(locations)
locations.map do |location|
2023-06-20 00:43:36 +05:30
matching = file_classes.map do |file_class|
2023-03-04 22:38:38 +05:30
file_class.new(location, context)
end.select(&:matching?)
if matching.one?
matching.first
elsif matching.empty?
raise Mapper::AmbigiousSpecificationError,
2023-04-23 21:23:45 +05:30
"`#{masked_location(location.to_json)}` does not have a valid subkey for include. " \
2023-06-20 00:43:36 +05:30
"Valid subkeys are: `#{file_subkeys.join('`, `')}`"
2023-03-04 22:38:38 +05:30
else
raise Mapper::AmbigiousSpecificationError,
2023-06-20 00:43:36 +05:30
"Each include must use only one of: `#{file_subkeys.join('`, `')}`"
2023-03-04 22:38:38 +05:30
end
end
end
def masked_location(location)
context.mask_variables_from(location)
end
2023-06-20 00:43:36 +05:30
def file_subkeys
file_classes.map { |f| f.name.demodulize.downcase }.freeze
end
strong_memoize_attr :file_subkeys
def file_classes
classes = [
External::File::Local,
External::File::Project,
External::File::Remote,
External::File::Template,
External::File::Artifact
]
if Feature.enabled?(:ci_include_components, context.project&.root_namespace)
classes << External::File::Component
end
classes
end
strong_memoize_attr :file_classes
2023-03-04 22:38:38 +05:30
end
end
end
end
end
end