summaryrefslogtreecommitdiff
path: root/lib/api/deployments.rb
blob: 548b57b50dc7cdf494537a5508b9413b6eae2554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module API
  # Deployments RESTful API endpoints
  class Deployments < Grape::API
    include PaginationParams

    before { authenticate! }

    params do
      requires :id, type: String, desc: 'The project ID'
    end
    resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
      desc 'Get all deployments of the project' do
        detail _('This feature was introduced in GitLab 8.11.')
        success Entities::Deployment
      end
      params do
        use :pagination
        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)'
      end
      # rubocop: disable CodeReuse/ActiveRecord
      get ':id/deployments' do
        authorize! :read_deployment, user_project

        present paginate(user_project.deployments.order(params[:order_by] => params[:sort])), with: Entities::Deployment
      end
      # rubocop: enable CodeReuse/ActiveRecord

      desc 'Gets a specific deployment' do
        detail _('This feature was introduced in GitLab 8.11.')
        success Entities::Deployment
      end
      params do
        requires :deployment_id, type: Integer,  desc: 'The deployment ID'
      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