summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-02-16 15:47:02 +0100
committerToon Claes <toon@gitlab.com>2017-03-02 12:15:24 +0100
commited8f13c745da849c319eb8e9d8fd3e59bb804a08 (patch)
treed9f88bd0a39b59d68cf4bb6e66dac8ffb4821005 /lib/api
parentf45cbc87015dd2e6369e758ca96132cb44c8983a (diff)
downloadgitlab-ce-ed8f13c745da849c319eb8e9d8fd3e59bb804a08.tar.gz
Ensure v3 environments endpoints remain unchanged
Because environments also expose the project, ensure the projects are exposed as they were before in API v3.
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/v3/entities.rb4
-rw-r--r--lib/api/v3/environments.rb62
2 files changed, 64 insertions, 2 deletions
diff --git a/lib/api/v3/entities.rb b/lib/api/v3/entities.rb
index 9c5a64a6c2f..da5b58cab9c 100644
--- a/lib/api/v3/entities.rb
+++ b/lib/api/v3/entities.rb
@@ -149,6 +149,10 @@ module API
expose :projects, using: Entities::Project
expose :shared_projects, using: Entities::Project
end
+
+ class Environment < ::API::Entities::EnvironmentBasic
+ expose :project, using: Entities::Project
+ end
end
end
end
diff --git a/lib/api/v3/environments.rb b/lib/api/v3/environments.rb
index 3effccfa708..3056b70e6ef 100644
--- a/lib/api/v3/environments.rb
+++ b/lib/api/v3/environments.rb
@@ -1,6 +1,7 @@
module API
module V3
class Environments < Grape::API
+ include ::API::Helpers::CustomValidators
include PaginationParams
before { authenticate! }
@@ -9,9 +10,66 @@ module API
requires :id, type: String, desc: 'The project ID'
end
resource :projects do
+ desc 'Get all environments of the project' do
+ detail 'This feature was introduced in GitLab 8.11.'
+ success Entities::Environment
+ end
+ params do
+ use :pagination
+ end
+ get ':id/environments' do
+ authorize! :read_environment, user_project
+
+ present paginate(user_project.environments), with: Entities::Environment
+ end
+
+ 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'
+ optional :slug, absence: { message: "is automatically generated and cannot be changed" }
+ end
+ post ':id/environments' do
+ authorize! :create_environment, user_project
+
+ environment = user_project.environments.create(declared_params)
+
+ if environment.persisted?
+ present environment, with: Entities::Environment
+ else
+ render_validation_error!(environment)
+ end
+ end
+
+ 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'
+ optional :slug, absence: { message: "is automatically generated and cannot be changed" }
+ end
+ put ':id/environments/:environment_id' do
+ authorize! :update_environment, user_project
+
+ environment = user_project.environments.find(params[:environment_id])
+
+ update_params = declared_params(include_missing: false).extract!(:name, :external_url)
+ 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 ::API::Entities::Environment
+ success Entities::Environment
end
params do
requires :environment_id, type: Integer, desc: 'The environment ID'
@@ -21,7 +79,7 @@ module API
environment = user_project.environments.find(params[:environment_id])
- present environment.destroy, with: ::API::Entities::Environment
+ present environment.destroy, with: Entities::Environment
end
end
end