2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
class TemplateFinder
|
2018-12-05 23:21:45 +05:30
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
VENDORED_TEMPLATES = HashWithIndifferentAccess.new(
|
2018-11-20 20:47:30 +05:30
|
|
|
dockerfiles: ::Gitlab::Template::DockerfileTemplate,
|
|
|
|
gitignores: ::Gitlab::Template::GitignoreTemplate,
|
2020-10-24 23:57:45 +05:30
|
|
|
gitlab_ci_ymls: ::Gitlab::Template::GitlabCiYmlTemplate,
|
|
|
|
metrics_dashboard_ymls: ::Gitlab::Template::MetricsDashboardTemplate,
|
|
|
|
issues: ::Gitlab::Template::IssueTemplate,
|
|
|
|
merge_requests: ::Gitlab::Template::MergeRequestTemplate
|
2018-12-05 23:21:45 +05:30
|
|
|
).freeze
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
class << self
|
2018-12-05 23:21:45 +05:30
|
|
|
def build(type, project, params = {})
|
|
|
|
if type.to_s == 'licenses'
|
|
|
|
LicenseTemplateFinder.new(project, params) # rubocop: disable CodeReuse/Finder
|
2018-11-20 20:47:30 +05:30
|
|
|
else
|
2018-12-05 23:21:45 +05:30
|
|
|
new(type, project, params)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
def all_template_names(project, type)
|
|
|
|
return {} if !VENDORED_TEMPLATES.key?(type.to_s) && type.to_s != 'licenses'
|
|
|
|
|
|
|
|
build(type, project).template_names
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
attr_reader :type, :project, :params
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
attr_reader :vendored_templates
|
|
|
|
private :vendored_templates
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
def initialize(type, project, params = {})
|
2018-11-20 20:47:30 +05:30
|
|
|
@type = type
|
2018-12-05 23:21:45 +05:30
|
|
|
@project = project
|
2018-11-20 20:47:30 +05:30
|
|
|
@params = params
|
|
|
|
|
|
|
|
@vendored_templates = VENDORED_TEMPLATES.fetch(type)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
if params[:name]
|
2020-10-24 23:57:45 +05:30
|
|
|
vendored_templates.find(params[:name], project)
|
2018-11-20 20:47:30 +05:30
|
|
|
else
|
2020-10-24 23:57:45 +05:30
|
|
|
vendored_templates.all(project)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
def template_names
|
|
|
|
vendored_templates.template_names(project)
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
TemplateFinder.prepend_mod_with('TemplateFinder')
|