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

52 lines
1.1 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
attr_reader :location, :project
2019-12-04 20:38:33 +05:30
SUFFIX = '.gitlab-ci.yml'
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
private
def validate_location!
super
unless template_name_valid?
errors.push("Template file `#{location}` is not a valid location!")
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
Gitlab::Template::GitlabCiYmlTemplate.find(template_name, project)&.content
end
end
end
end
end
end
end