2018-09-29 22:34:47 +00:00
# frozen_string_literal: true
2016-08-16 06:45:23 +00:00
module API
2017-03-06 17:19:15 +00:00
# Deployments RESTful API endpoints
2016-08-16 06:45:23 +00:00
class Deployments < Grape :: API
2016-11-21 19:15:46 +00:00
include PaginationParams
2016-08-16 06:45:23 +00:00
before { authenticate! }
params do
requires :id , type : String , desc : 'The project ID'
end
2018-11-08 12:18:17 +00:00
resource :projects , requirements : API :: NAMESPACE_OR_PROJECT_REQUIREMENTS do
2016-08-16 06:45:23 +00:00
desc 'Get all deployments of the project' do
detail 'This feature was introduced in GitLab 8.11.'
success Entities :: Deployment
end
params do
2016-11-21 19:15:46 +00:00
use :pagination
2018-01-11 16:45:35 +00:00
optional :order_by , type : String , values : %w[ id iid created_at ref ] , default : 'id' , desc : 'Return deployments ordered by `id` or `iid` or `created_at` or `ref`'
optional :sort , type : String , values : %w[ asc desc ] , default : 'asc' , desc : 'Sort by asc (ascending) or desc (descending)'
2016-08-16 06:45:23 +00:00
end
2018-08-27 15:31:01 +00:00
# rubocop: disable CodeReuse/ActiveRecord
2016-08-16 06:45:23 +00:00
get ':id/deployments' do
authorize! :read_deployment , user_project
2018-01-11 16:45:35 +00:00
present paginate ( user_project . deployments . order ( params [ :order_by ] = > params [ :sort ] ) ) , with : Entities :: Deployment
2016-08-16 06:45:23 +00:00
end
2018-08-27 15:31:01 +00:00
# rubocop: enable CodeReuse/ActiveRecord
2016-08-16 06:45:23 +00:00
desc 'Gets a specific deployment' do
detail 'This feature was introduced in GitLab 8.11.'
success Entities :: Deployment
end
params do
2019-01-16 12:09:29 +00:00
requires :deployment_id , type : Integer , desc : 'The deployment ID'
2016-08-16 06:45:23 +00:00
end
get ':id/deployments/:deployment_id' do
authorize! :read_deployment , user_project
deployment = user_project . deployments . find ( params [ :deployment_id ] )
present deployment , with : Entities :: Deployment
end
end
end
end