Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <zegerjan@gitlab.com>2016-07-29 13:14:36 +0300
committerZ.J. van de Weg <zegerjan@gitlab.com>2016-07-29 21:35:38 +0300
commit1b72256fa14e65256d78347f81b289d43c44e991 (patch)
tree923e3597ad8b0199d77f57331bd44e7b81251bdd /lib/api/environments.rb
parent76e9b68439510af5c783a81b93944f1c8d96d150 (diff)
Use Grape DSL for environment endpoints
Also a couple of minor edits for this branch are included
Diffstat (limited to 'lib/api/environments.rb')
-rw-r--r--lib/api/environments.rb91
1 files changed, 43 insertions, 48 deletions
diff --git a/lib/api/environments.rb b/lib/api/environments.rb
index 532baec42c7..a50f007d697 100644
--- a/lib/api/environments.rb
+++ b/lib/api/environments.rb
@@ -3,82 +3,77 @@ module API
class Environments < Grape::API
before { authenticate! }
+ params do
+ requires :id, type: String, desc: 'The project ID'
+ end
resource :projects do
- # Get all labels of the project
- #
- # Parameters:
- # id (required) - The ID of a project
- # Example Request:
- # GET /projects/:id/environments
+ desc 'Get all environments of the project' do
+ detail 'This feature was introduced in GitLab 8.11.'
+ success Entities::Environment
+ end
get ':id/environments' do
authorize! :read_environment, user_project
present paginate(user_project.environments), with: Entities::Environment
end
- # Creates a new environment
- #
- # Parameters:
- # id (required) - The ID of a project
- # name (required) - The name of the environment to be created
- # external_url (optional) - URL on which this deployment is viewable
- #
- # Example Request:
- # POST /projects/:id/labels
+ desc 'Creates a new environment' do
+ detail 'This feature was introduced in GitLab 8.11.'
+ success Entities::Environment
+ end
+ params do
+ requires :name, type: String, desc: 'The name of the environment to be created'
+ optional :external_url, type: String, desc: 'URL on which this deployment is viewable'
+ end
post ':id/environments' do
authorize! :create_environment, user_project
- required_attributes! [:name]
-
- attrs = attributes_for_keys [:name, :external_url]
- environment = user_project.environments.create(attrs)
+ create_params = declared(params, include_parent_namespaces: false).to_h
+ environment = user_project.environments.create(create_params)
- if environment.valid?
+ if environment.persisted?
present environment, with: Entities::Environment
else
render_validation_error!(environment)
end
end
- # Deletes an existing environment
- #
- # Parameters:
- # id (required) - The ID of a project
- # environment_id (required) - The name of the environment to be deleted
- #
- # Example Request:
- # DELETE /projects/:id/environments/:environment_id
- delete ':id/environments/:environment_id' do
- authorize! :update_environment, user_project
-
- environment = user_project.environments.find(params[:environment_id])
-
- present environment.destroy, with: Entities::Environment
+ desc 'Updates an existing environment' do
+ detail 'This feature was introduced in GitLab 8.11.'
+ success Entities::Environment
+ end
+ params do
+ requires :environment_id, type: Integer, desc: 'The environment ID'
+ optional :name, type: String, desc: 'The new environment name'
+ optional :external_url, type: String, desc: 'The new URL on which this deployment is viewable'
end
-
- # Updates an existing environment
- #
- # Parameters:
- # id (required) - The ID of a project
- # environment_id (required) - The ID of the environment
- # name (optional) - The name of the label to be deleted
- # external_url (optional) - The new name of the label
- #
- # Example Request:
- # PUT /projects/:id/environments/:environment_id
put ':id/environments/:environment_id' do
authorize! :update_environment, user_project
environment = user_project.environments.find(params[:environment_id])
- attrs = attributes_for_keys [:name, :external_url]
-
- if environment.update(attrs)
+ update_params = declared(params, include_missing: false).extract!(:name, :external_url).to_h
+ if environment.update(update_params)
present environment, with: Entities::Environment
else
render_validation_error!(environment)
end
end
+
+ desc 'Deletes an existing environment' do
+ detail 'This feature was introduced in GitLab 8.11.'
+ success Entities::Environment
+ end
+ params do
+ requires :environment_id, type: Integer, desc: 'The environment ID'
+ end
+ delete ':id/environments/:environment_id' do
+ authorize! :update_environment, user_project
+
+ environment = user_project.environments.find(params[:environment_id])
+
+ present environment.destroy, with: Entities::Environment
+ end
end
end
end