2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-28 09:14:39 -04:00
|
|
|
class TemplateFinder
|
2018-10-02 19:00:38 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
VENDORED_TEMPLATES = HashWithIndifferentAccess.new(
|
2018-08-28 09:14:39 -04:00
|
|
|
dockerfiles: ::Gitlab::Template::DockerfileTemplate,
|
|
|
|
gitignores: ::Gitlab::Template::GitignoreTemplate,
|
2020-08-03 05:09:42 -04:00
|
|
|
gitlab_ci_ymls: ::Gitlab::Template::GitlabCiYmlTemplate,
|
2020-08-11 23:10:17 -04:00
|
|
|
metrics_dashboard_ymls: ::Gitlab::Template::MetricsDashboardTemplate,
|
|
|
|
issues: ::Gitlab::Template::IssueTemplate,
|
|
|
|
merge_requests: ::Gitlab::Template::MergeRequestTemplate
|
2018-10-02 19:00:38 -04:00
|
|
|
).freeze
|
2018-08-28 09:14:39 -04:00
|
|
|
|
2018-09-05 09:45:02 -04:00
|
|
|
class << self
|
2018-10-02 19:00:38 -04:00
|
|
|
def build(type, project, params = {})
|
|
|
|
if type.to_s == 'licenses'
|
|
|
|
LicenseTemplateFinder.new(project, params) # rubocop: disable CodeReuse/Finder
|
2018-09-05 09:45:02 -04:00
|
|
|
else
|
2018-10-02 19:00:38 -04:00
|
|
|
new(type, project, params)
|
2018-09-05 09:45:02 -04:00
|
|
|
end
|
|
|
|
end
|
2021-02-08 13:09:49 -05:00
|
|
|
|
|
|
|
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-09-05 09:45:02 -04:00
|
|
|
end
|
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
attr_reader :type, :project, :params
|
2018-08-28 09:14:39 -04:00
|
|
|
|
|
|
|
attr_reader :vendored_templates
|
|
|
|
private :vendored_templates
|
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
def initialize(type, project, params = {})
|
2018-08-28 09:14:39 -04:00
|
|
|
@type = type
|
2018-10-02 19:00:38 -04:00
|
|
|
@project = project
|
2018-08-28 09:14:39 -04:00
|
|
|
@params = params
|
|
|
|
|
|
|
|
@vendored_templates = VENDORED_TEMPLATES.fetch(type)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
if params[:name]
|
2020-08-11 23:10:17 -04:00
|
|
|
vendored_templates.find(params[:name], project)
|
2018-08-28 09:14:39 -04:00
|
|
|
else
|
2020-08-11 23:10:17 -04:00
|
|
|
vendored_templates.all(project)
|
2018-08-28 09:14:39 -04:00
|
|
|
end
|
|
|
|
end
|
2021-02-08 13:09:49 -05:00
|
|
|
|
|
|
|
def template_names
|
|
|
|
vendored_templates.template_names(project)
|
|
|
|
end
|
2018-08-28 09:14:39 -04:00
|
|
|
end
|
2020-04-10 08:09:36 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
TemplateFinder.prepend_mod_with('TemplateFinder')
|