Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-11 22:12:04 +0300
committerShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-30 17:55:08 +0300
commitfbd3b3d8a245072121784df11b7b41d3257b989f (patch)
tree53fd84be85bd74545d59433b1b5fcf61f5d4910e /lib
parenta16cbab3bb371941f51c3c4178b8b807de000ca8 (diff)
Add API support for pipeline schedule
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/entities.rb8
-rw-r--r--lib/api/pipeline_schedules.rb127
3 files changed, 136 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index ac113c5200d..bbdd2039f43 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -110,6 +110,7 @@ module API
mount ::API::Notes
mount ::API::NotificationSettings
mount ::API::Pipelines
+ mount ::API::PipelineSchedules
mount ::API::ProjectHooks
mount ::API::Projects
mount ::API::ProjectSnippets
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 8c5e5c91769..1f1942b2ec1 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -686,6 +686,14 @@ module API
expose :coverage
end
+ class PipelineSchedule < Grape::Entity
+ expose :id
+ expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active
+ expose :created_at, :updated_at, :deleted_at
+ expose :last_pipeline, using: Entities::Pipeline, if: -> (pipeline_schedule, opts) { pipeline_schedule.last_pipeline.present? }
+ expose :owner, using: Entities::UserBasic
+ end
+
class EnvironmentBasic < Grape::Entity
expose :id, :name, :slug, :external_url
end
diff --git a/lib/api/pipeline_schedules.rb b/lib/api/pipeline_schedules.rb
new file mode 100644
index 00000000000..32fa5a86fab
--- /dev/null
+++ b/lib/api/pipeline_schedules.rb
@@ -0,0 +1,127 @@
+module API
+ class PipelineSchedules < Grape::API
+ include PaginationParams
+
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ end
+ resource :projects, requirements: { id: %r{[^/]+} } do
+ desc 'Get pipeline_schedules list' do
+ success Entities::PipelineSchedule
+ end
+ params do
+ use :pagination
+ end
+ get ':id/pipeline_schedules' do
+ authenticate!
+ authorize! :read_pipeline_schedule, user_project
+
+ pipeline_schedules = user_project.pipeline_schedules
+
+ present paginate(pipeline_schedules), with: Entities::PipelineSchedule
+ end
+
+ desc 'Get specific pipeline_schedule of a project' do
+ success Entities::PipelineSchedule
+ end
+ params do
+ requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline_schedule ID'
+ end
+ get ':id/pipeline_schedules/:pipeline_schedule_id' do
+ authenticate!
+ authorize! :read_pipeline_schedule, user_project
+
+ pipeline_schedule = user_project.pipeline_schedules.find(params.delete(:pipeline_schedule_id))
+ return not_found!('PipelineSchedule') unless pipeline_schedule
+
+ present pipeline_schedule, with: Entities::PipelineSchedule
+ end
+
+ desc 'Create a pipeline_schedule' do
+ success Entities::PipelineSchedule
+ end
+ params do
+ requires :description, type: String, desc: 'The pipeline_schedule description'
+ requires :ref, type: String, desc: 'The pipeline_schedule ref'
+ requires :cron, type: String, desc: 'The pipeline_schedule cron'
+ requires :cron_timezone, type: String, desc: 'The pipeline_schedule cron_timezone'
+ requires :active, type: Boolean, desc: 'The pipeline_schedule active'
+ end
+ post ':id/pipeline_schedules' do
+ authenticate!
+ authorize! :create_pipeline_schedule, user_project
+
+ pipeline_schedule = user_project.pipeline_schedules.create(
+ declared_params(include_missing: false).merge(owner: current_user))
+
+ if pipeline_schedule.valid?
+ present pipeline_schedule, with: Entities::PipelineSchedule
+ else
+ render_validation_error!(pipeline_schedule)
+ end
+ end
+
+ desc 'Update a pipeline_schedule' do
+ success Entities::PipelineSchedule
+ end
+ params do
+ requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline_schedule ID'
+ optional :description, type: String, desc: 'The pipeline_schedule description'
+ optional :ref, type: String, desc: 'The pipeline_schedule ref'
+ optional :cron, type: String, desc: 'The pipeline_schedule cron'
+ optional :cron_timezone, type: String, desc: 'The pipeline_schedule cron_timezone'
+ optional :active, type: Boolean, desc: 'The pipeline_schedule active'
+ end
+ put ':id/pipeline_schedules/:pipeline_schedule_id' do
+ authenticate!
+ authorize! :create_pipeline_schedule, user_project
+
+ pipeline_schedule = user_project.pipeline_schedules.find(params.delete(:pipeline_schedule_id))
+ return not_found!('PipelineSchedule') unless pipeline_schedule
+
+ if pipeline_schedule.update(declared_params(include_missing: false))
+ present pipeline_schedule, with: Entities::PipelineSchedule
+ else
+ render_validation_error!(pipeline_schedule)
+ end
+ end
+
+ desc 'Take ownership of pipeline_schedule' do
+ success Entities::PipelineSchedule
+ end
+ params do
+ requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline_schedule ID'
+ end
+ post ':id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do
+ authenticate!
+ authorize! :create_pipeline_schedule, user_project
+
+ pipeline_schedule = user_project.pipeline_schedules.find(params.delete(:pipeline_schedule_id))
+ return not_found!('PipelineSchedule') unless pipeline_schedule
+
+ if pipeline_schedule.update(owner: current_user)
+ status :ok
+ present pipeline_schedule, with: Entities::PipelineSchedule
+ else
+ render_validation_error!(pipeline_schedule)
+ end
+ end
+
+ desc 'Delete a pipeline_schedule' do
+ success Entities::PipelineSchedule
+ end
+ params do
+ requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline_schedule ID'
+ end
+ delete ':id/pipeline_schedules/:pipeline_schedule_id' do
+ authenticate!
+ authorize! :admin_pipeline_schedule, user_project
+
+ pipeline_schedule = user_project.pipeline_schedules.find(params.delete(:pipeline_schedule_id))
+ return not_found!('PipelineSchedule') unless pipeline_schedule
+
+ present pipeline_schedule.destroy, with: Entities::PipelineSchedule
+ end
+ end
+ end
+end