PageRenderTime 47ms CodeModel.GetById 27ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/api/pipelines.rb

https://gitlab.com/vicvega/gitlab-ce
Ruby | 77 lines | 66 code | 11 blank | 0 comment | 0 complexity | 471b1b265d4e590f7b92f2e7055c7093 MD5 | raw file
 1module API
 2  class Pipelines < Grape::API
 3    before { authenticate! }
 4
 5    params do
 6      requires :id, type: String, desc: 'The project ID'
 7    end
 8    resource :projects do
 9      desc 'Get all Pipelines of the project' do
10        detail 'This feature was introduced in GitLab 8.11.'
11        success Entities::Pipeline
12      end
13      params do
14        optional :page,     type: Integer, desc: 'Page number of the current request'
15        optional :per_page, type: Integer, desc: 'Number of items per page'
16        optional :scope,    type: String, values: ['running', 'branches', 'tags'],
17                            desc: 'Either running, branches, or tags'
18      end
19      get ':id/pipelines' do
20        authorize! :read_pipeline, user_project
21
22        pipelines = PipelinesFinder.new(user_project).execute(scope: params[:scope])
23        present paginate(pipelines), with: Entities::Pipeline
24      end
25
26      desc 'Gets a specific pipeline for the project' do
27        detail 'This feature was introduced in GitLab 8.11'
28        success Entities::Pipeline
29      end
30      params do
31        requires :pipeline_id, type: Integer, desc: 'The pipeline ID'
32      end
33      get ':id/pipelines/:pipeline_id' do
34        authorize! :read_pipeline, user_project
35
36        present pipeline, with: Entities::Pipeline
37      end
38
39      desc 'Retry failed builds in the pipeline' do
40        detail 'This feature was introduced in GitLab 8.11.'
41        success Entities::Pipeline
42      end
43      params do
44        requires :pipeline_id, type: Integer,  desc: 'The pipeline ID'
45      end
46      post ':id/pipelines/:pipeline_id/retry' do
47        authorize! :update_pipeline, user_project
48
49        pipeline.retry_failed(current_user)
50
51        present pipeline, with: Entities::Pipeline
52      end
53
54      desc 'Cancel all builds in the pipeline' do
55        detail 'This feature was introduced in GitLab 8.11.'
56        success Entities::Pipeline
57      end
58      params do
59        requires :pipeline_id, type: Integer,  desc: 'The pipeline ID'
60      end
61      post ':id/pipelines/:pipeline_id/cancel' do
62        authorize! :update_pipeline, user_project
63
64        pipeline.cancel_running
65
66        status 200
67        present pipeline.reload, with: Entities::Pipeline
68      end
69    end
70
71    helpers do
72      def pipeline
73        @pipeline ||= user_project.pipelines.find(params[:pipeline_id])
74      end
75    end
76  end
77end