debian-mirror-gitlab/app/finders/template_finder.rb

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

69 lines
1.7 KiB
Ruby
Raw Normal View History

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
2023-07-09 08:55:56 +05:30
elsif type_allowed?(type)
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)
2023-07-09 08:55:56 +05:30
return {} unless type_allowed?(type)
2021-03-11 19:13:27 +05:30
build(type, project).template_names
end
2023-07-09 08:55:56 +05:30
def type_allowed?(type)
case type.to_s
when 'licenses'
true
when 'metrics_dashboard_ymls'
!Feature.enabled?(:remove_monitor_metrics)
else
VENDORED_TEMPLATES.key?(type)
end
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')