summaryrefslogtreecommitdiff
path: root/lib/api/templates.rb
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-06-24 16:43:46 -0300
committerFelipe Artur <felipefac@gmail.com>2016-08-16 15:50:17 -0300
commit28726729452ef64270534806e75a9595ea1a659d (patch)
tree7f9144f88c1fa9935f3d05d50ab9b1bcc4e7558d /lib/api/templates.rb
parent7f853e2245eff92c037af5e007163d3e9631888d (diff)
downloadgitlab-ce-28726729452ef64270534806e75a9595ea1a659d.tar.gz
Load issues and merge requests templates from repository
Diffstat (limited to 'lib/api/templates.rb')
-rw-r--r--lib/api/templates.rb26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/api/templates.rb b/lib/api/templates.rb
index 18408797756..b9e718147e1 100644
--- a/lib/api/templates.rb
+++ b/lib/api/templates.rb
@@ -1,21 +1,28 @@
module API
class Templates < Grape::API
- TEMPLATE_TYPES = {
- gitignores: Gitlab::Template::Gitignore,
- gitlab_ci_ymls: Gitlab::Template::GitlabCiYml
+ GLOBAL_TEMPLATE_TYPES = {
+ gitignores: Gitlab::Template::GitignoreTemplate,
+ gitlab_ci_ymls: Gitlab::Template::GitlabCiYmlTemplate
}.freeze
- TEMPLATE_TYPES.each do |template, klass|
+ helpers do
+ def render_response(template_type, template)
+ not_found!(template_type.to_s.singularize) unless template
+ present template, with: Entities::Template
+ end
+ end
+
+ GLOBAL_TEMPLATE_TYPES.each do |template_type, klass|
# Get the list of the available template
#
# Example Request:
# GET /gitignores
# GET /gitlab_ci_ymls
- get template.to_s do
+ get template_type.to_s do
present klass.all, with: Entities::TemplatesList
end
- # Get the text for a specific template
+ # Get the text for a specific template present in local filesystem
#
# Parameters:
# name (required) - The name of a template
@@ -23,13 +30,10 @@ module API
# Example Request:
# GET /gitignores/Elixir
# GET /gitlab_ci_ymls/Ruby
- get "#{template}/:name" do
+ get "#{template_type}/:name" do
required_attributes! [:name]
-
new_template = klass.find(params[:name])
- not_found!(template.to_s.singularize) unless new_template
-
- present new_template, with: Entities::Template
+ render_response(template_type, new_template)
end
end
end