Files
gitlabhq/lib/api/templates.rb
T
Jacob SchatzandRobert Speicher 355310ba98 Merge branch '17521-gitlab-ci-yml-templates' into 'master'
GitLab CI Yaml template dropdown

## What does this MR do?
Make it possible to select a dropdown for an easy start with GitLab CI.

## What are the relevant issue numbers?
Closes #17521

## TODO
- [ ] Backend
  - [x] CHANGELOG item
  - [x] Fix rubocop failure
  - [x] API Support
  - [x] New tests
  - [x] Add disclaimer to the top of the gitlab-ci.yml
- [ ] Frontend
  - [x] New tests

See merge request !4411
2016-06-21 12:17:47 -04:00

37 lines
953 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