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

template.rb « file « external « config « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 53236cb317b12ba52f9a6fef5f971def4bcf00d9 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      module External
        module File
          class Template < Base
            attr_reader :location

            SUFFIX = '.gitlab-ci.yml'
            HOST = 'https://gitlab.com/gitlab-org/gitlab/-/raw/master'

            def initialize(params, context)
              @location = params[:template]

              super
            end

            def content
              strong_memoize(:content) { fetch_template_content }
            end

            def metadata
              super.merge(
                type: :template,
                location: masked_location,
                blob: nil,
                raw: masked_raw,
                extra: {}
              )
            end

            private

            def validate_context!
              # no-op
            end

            def validate_location!
              super

              unless template_name_valid?
                errors.push("Template file `#{masked_location}` is not a valid location!")
              end
            end

            def template_name
              return unless template_name_valid?

              location.delete_suffix(SUFFIX)
            end

            def template_name_valid?
              location.to_s.end_with?(SUFFIX)
            end

            def fetch_template_content
              context.logger.instrument(:config_file_fetch_template_content) do
                Gitlab::Template::GitlabCiYmlTemplate.find(template_name, context.project)&.content
              end
            end

            def masked_raw
              strong_memoize(:masked_raw) do
                context.mask_variables_from(
                  "#{HOST}/#{Gitlab::Template::GitlabCiYmlTemplate::BASE_DIR}/#{location}"
                )
              end
            end
          end
        end
      end
    end
  end
end