Welcome to mirror list, hosted at ThFree Co, Russian Federation.

matcher.rb « mapper « external « config « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 85e19ff1ced7bf82a56afa224243c2d10bea266b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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
            FILE_CLASSES = [
              External::File::Local,
              External::File::Project,
              External::File::Remote,
              External::File::Template,
              External::File::Artifact
            ].freeze

            FILE_SUBKEYS = FILE_CLASSES.map { |f| f.name.demodulize.downcase }.freeze

            private

            def process_without_instrumentation(locations)
              locations.map do |location|
                matching = FILE_CLASSES.map do |file_class|
                  file_class.new(location, context)
                end.select(&:matching?)

                if matching.one?
                  matching.first
                elsif matching.empty?
                  raise Mapper::AmbigiousSpecificationError,
                        "`#{masked_location(location.to_json)}` does not have a valid subkey for include. " \
                        "Valid subkeys are: `#{FILE_SUBKEYS.join('`, `')}`"
                else
                  raise Mapper::AmbigiousSpecificationError,
                        "Each include must use only one of: `#{FILE_SUBKEYS.join('`, `')}`"
                end
              end
            end

            def masked_location(location)
              context.mask_variables_from(location)
            end
          end
        end
      end
    end
  end
end