debian-mirror-gitlab/lib/gitlab/ci/config/external/file/template.rb

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

73 lines
1.8 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module External
module File
class Template < Base
2021-09-04 01:27:46 +05:30
attr_reader :location
2019-02-15 15:39:39 +05:30
2019-12-04 20:38:33 +05:30
SUFFIX = '.gitlab-ci.yml'
2022-07-16 23:28:13 +05:30
HOST = 'https://gitlab.com/gitlab-org/gitlab/-/raw/master'
2019-02-15 15:39:39 +05:30
def initialize(params, context)
@location = params[:template]
super
end
def content
strong_memoize(:content) { fetch_template_content }
end
2022-06-21 17:19:12 +05:30
def metadata
super.merge(
type: :template,
location: masked_location,
2022-07-16 23:28:13 +05:30
blob: nil,
raw: masked_raw,
2022-06-21 17:19:12 +05:30
extra: {}
)
end
2019-02-15 15:39:39 +05:30
private
def validate_location!
super
unless template_name_valid?
2022-04-01 21:47:47 +05:30
errors.push("Template file `#{masked_location}` is not a valid location!")
2019-02-15 15:39:39 +05:30
end
end
def template_name
return unless template_name_valid?
2020-03-13 15:44:24 +05:30
location.delete_suffix(SUFFIX)
2019-02-15 15:39:39 +05:30
end
def template_name_valid?
location.to_s.end_with?(SUFFIX)
end
def fetch_template_content
2022-07-23 23:45:48 +05:30
context.logger.instrument(:config_file_fetch_template_content) do
Gitlab::Template::GitlabCiYmlTemplate.find(template_name, context.project)&.content
end
2019-02-15 15:39:39 +05:30
end
2022-07-16 23:28:13 +05:30
def masked_raw
strong_memoize(:masked_raw) do
context.mask_variables_from(
"#{HOST}/#{Gitlab::Template::GitlabCiYmlTemplate::BASE_DIR}/#{location}"
)
end
end
2019-02-15 15:39:39 +05:30
end
end
end
end
end
end