mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-18 00:56:41 +10:00
This commit builds on the groundwork in ee008e300b1ec0abcc90e6a30816ec0754cea0dd, which refactored the backend so the same code could be used for new dropdowns. In this commit its used for templates for the `.gitlab-ci.yml` files.
37 lines
958 B
Ruby
37 lines
958 B
Ruby
module API
|
|
class Templates < Grape::API
|
|
TEMPLATE_TYPES = {
|
|
gitignores: Gitlab::Template::Gitignore,
|
|
gitlab_ci_ymls: Gitlab::Template::GitlabCIYml
|
|
}.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
|
|
|
|
present new_template, with: Entities::Template
|
|
end
|
|
end
|
|
end
|
|
end
|