/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

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