summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorKrasimir Angelov <kangelov@gitlab.com>2019-04-09 09:16:57 +0000
committerKamil TrzciƄski <ayufan@ayufan.eu>2019-04-09 09:16:57 +0000
commit724f19ba0a051bbe8e9dd89f208261abe0f8133a (patch)
tree111955bd4ca355100c3d97758b42e942ea4c1779 /lib/api
parente70fae8d8db6a4c4a8d5498bcac039424eb941c1 (diff)
downloadgitlab-ce-724f19ba0a051bbe8e9dd89f208261abe0f8133a.tar.gz
Add new API endpoint to expose single environment
This is resolving https://gitlab.com/gitlab-org/gitlab-ce/issues/30157. Implement new API endpoint `/projects/:id/environments/:environment_id` to expose single environment. Include information for environment's last deployment if there is one.
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/entities.rb9
-rw-r--r--lib/api/environments.rb15
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 2dd3120d3fc..f9773086f69 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -1294,10 +1294,6 @@ module API
expose :id, :name, :slug, :external_url
end
- class Environment < EnvironmentBasic
- expose :project, using: Entities::BasicProjectDetails
- end
-
class Deployment < Grape::Entity
expose :id, :iid, :ref, :sha, :created_at
expose :user, using: Entities::UserBasic
@@ -1305,6 +1301,11 @@ module API
expose :deployable, using: Entities::Job
end
+ class Environment < EnvironmentBasic
+ expose :project, using: Entities::BasicProjectDetails
+ expose :last_deployment, using: Entities::Deployment, if: { last_deployment: true }
+ end
+
class LicenseBasic < Grape::Entity
expose :key, :name, :nickname
expose :url, as: :html_url
diff --git a/lib/api/environments.rb b/lib/api/environments.rb
index 5b0f3b914cb..6cd43923559 100644
--- a/lib/api/environments.rb
+++ b/lib/api/environments.rb
@@ -101,6 +101,21 @@ module API
status 200
present environment, with: Entities::Environment, current_user: current_user
end
+
+ desc 'Get a single environment' do
+ success Entities::Environment
+ end
+ params do
+ requires :environment_id, type: Integer, desc: 'The environment ID'
+ end
+ get ':id/environments/:environment_id' do
+ authorize! :read_environment, user_project
+
+ environment = user_project.environments.find(params[:environment_id])
+ present environment, with: Entities::Environment, current_user: current_user,
+ except: [:project, { last_deployment: [:environment] }],
+ last_deployment: true
+ end
end
end
end