diff options
author | ZJ van de Weg <zegerjan@gitlab.com> | 2016-05-27 11:00:56 +0200 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-06-20 14:48:28 -0500 |
commit | 27bf7ae59eb95bff0254b8ad3c001ea2397ec544 (patch) | |
tree | 111f9defe358890bf97926378d32ca5c2ed9f630 /lib/api | |
parent | 74f8f260982a9b9e1941ad803d53d229cc27c85f (diff) | |
download | gitlab-ce-27bf7ae59eb95bff0254b8ad3c001ea2397ec544.tar.gz |
Refactor Gitlab::Gitignores
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 2 | ||||
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/gitignores.rb | 29 | ||||
-rw-r--r-- | lib/api/templates.rb | 35 |
4 files changed, 38 insertions, 32 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 0e7a1cc2623..f8f680a6311 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -33,7 +33,6 @@ module API mount ::API::Commits mount ::API::DeployKeys mount ::API::Files - mount ::API::Gitignores mount ::API::GroupMembers mount ::API::Groups mount ::API::Internal @@ -58,6 +57,7 @@ module API mount ::API::Subscriptions mount ::API::SystemHooks mount ::API::Tags + mount ::API::Templates mount ::API::Triggers mount ::API::Users mount ::API::Variables diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 2e397643ed1..0c9fc5604fd 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -472,11 +472,11 @@ module API expose :content end - class GitignoresList < Grape::Entity + class TemplatesList < Grape::Entity expose :name end - class Gitignore < Grape::Entity + class Template < Grape::Entity expose :name, :content end end diff --git a/lib/api/gitignores.rb b/lib/api/gitignores.rb deleted file mode 100644 index 270c9501dd2..00000000000 --- a/lib/api/gitignores.rb +++ /dev/null @@ -1,29 +0,0 @@ -module API - class Gitignores < Grape::API - - # Get the list of the available gitignore templates - # - # Example Request: - # GET /gitignores - get 'gitignores' do - present Gitlab::Gitignore.all, with: Entities::GitignoresList - end - - # Get the text for a specific gitignore - # - # Parameters: - # name (required) - The name of a license - # - # Example Request: - # GET /gitignores/Elixir - # - get 'gitignores/:name' do - required_attributes! [:name] - - gitignore = Gitlab::Gitignore.find(params[:name]) - not_found!('.gitignore') unless gitignore - - present gitignore, with: Entities::Gitignore - end - end -end diff --git a/lib/api/templates.rb b/lib/api/templates.rb new file mode 100644 index 00000000000..4c770c0b9dd --- /dev/null +++ b/lib/api/templates.rb @@ -0,0 +1,35 @@ +module API + class Templates < Grape::API + TEMPLATE_TYPES = { + gitignores: Gitlab::Template::Gitignore + }.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 |