2016-05-27 09:00:56 +00:00
|
|
|
module API
|
|
|
|
class Templates < Grape::API
|
|
|
|
TEMPLATE_TYPES = {
|
2016-06-02 16:20:08 +00:00
|
|
|
gitignores: Gitlab::Template::Gitignore,
|
2016-06-16 13:33:11 +00:00
|
|
|
gitlab_ci_ymls: Gitlab::Template::GitlabCiYml
|
2016-05-27 09:00:56 +00:00
|
|
|
}.freeze
|
|
|
|
|
|
|
|
TEMPLATE_TYPES.each do |template, klass|
|
|
|
|
# Get the list of the available template
|
|
|
|
#
|
|
|
|
# Example Request:
|
|
|
|
# GET /gitignores
|
|
|
|
# GET /gitlab_ci_ymls
|
|
|
|
get template.to_s do
|
|
|
|
present klass.all, with: Entities::TemplatesList
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get the text for a specific template
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# name (required) - The name of a template
|
|
|
|
#
|
|
|
|
# Example Request:
|
|
|
|
# GET /gitignores/Elixir
|
|
|
|
# GET /gitlab_ci_ymls/Ruby
|
|
|
|
get "#{template}/:name" do
|
|
|
|
required_attributes! [:name]
|
|
|
|
|
|
|
|
new_template = klass.find(params[:name])
|
|
|
|
not_found!("#{template.to_s.singularize}") unless new_template
|
|
|
|
|
2016-06-16 13:33:11 +00:00
|
|
|
if new_template.class == Gitlab::Template::GitlabCiYml
|
|
|
|
new_template.content = "# This file is a template, and might need editing before it works on your project.\n" + new_template.content
|
|
|
|
end
|
|
|
|
|
2016-05-27 09:00:56 +00:00
|
|
|
present new_template, with: Entities::Template
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|