summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-08-18 17:25:35 +0900
committerShinya Maeda <shinya@gitlab.com>2017-09-04 21:10:34 +0900
commit8ca5c333fd5170a900c7fa28b6bfcbe1a8bc6477 (patch)
tree4754644a463464ccda3dee28d7d822dc4110b404 /lib/api
parent970af9964ea9404942818d8c3394d2903955ed69 (diff)
downloadgitlab-ce-8ca5c333fd5170a900c7fa28b6bfcbe1a8bc6477.tar.gz
Extend API: Pipeline Schedule Variable
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/entities.rb3
-rw-r--r--lib/api/pipeline_schedules.rb70
2 files changed, 72 insertions, 1 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index f13f2d723bb..09d7d9ad349 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -819,7 +819,7 @@ module API
class Variable < Grape::Entity
expose :key, :value
- expose :protected?, as: :protected
+ expose :protected?, as: :protected, if: -> (entity, options) { entity.respond_to?(protected?) }
end
class Pipeline < PipelineBasic
@@ -840,6 +840,7 @@ module API
class PipelineScheduleDetails < PipelineSchedule
expose :last_pipeline, using: Entities::PipelineBasic
+ expose :variables, using: Entities::Variable
end
class EnvironmentBasic < Grape::Entity
diff --git a/lib/api/pipeline_schedules.rb b/lib/api/pipeline_schedules.rb
index ef01cbc7875..e82b974c8cd 100644
--- a/lib/api/pipeline_schedules.rb
+++ b/lib/api/pipeline_schedules.rb
@@ -119,6 +119,76 @@ module API
destroy_conditionally!(pipeline_schedule)
end
+
+ params do
+ requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
+ end
+ resource :variables, requirements: { pipeline_schedule_id: %r{[^/]+} } do
+ desc 'Create a new pipeline schedule variable' do
+ success Entities::PipelineScheduleDetails
+ end
+ params do
+ requires :key, type: String, desc: 'The key of the variable'
+ requires :value, type: String, desc: 'The value of the variable'
+ end
+ post ':id/pipeline_schedules/:pipeline_schedule_id/variables' do
+ authorize! :read_pipeline_schedule, user_project
+
+ not_found!('PipelineSchedule') unless pipeline_schedule
+ authorize! :update_pipeline_schedule, pipeline_schedule
+
+ variable_params = declared_params(include_missing: false)
+ variable = pipeline_schedule.variables.create(variable_params)
+
+ if variable.persisted?
+ present variable, with: Entities::Variable
+ else
+ render_validation_error!(variable)
+ end
+ end
+
+ desc 'Edit a pipeline schedule variable' do
+ success Entities::PipelineScheduleDetails
+ end
+ params do
+ optional :key, type: String, desc: 'The key of the variable'
+ optional :value, type: String, desc: 'The value of the variable'
+ end
+ put ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do
+ authorize! :read_pipeline_schedule, user_project
+
+ not_found!('PipelineSchedule') unless pipeline_schedule
+ authorize! :update_pipeline_schedule, pipeline_schedule
+
+ variable = pipeline_schedule.variables.find_by(key: params[:key])
+ not_found!('Variable') unless variable
+
+ if variable.update(declared_params(include_missing: false))
+ present variable, with: Entities::Variable
+ else
+ render_validation_error!(variable)
+ end
+ end
+
+ desc 'Delete a pipeline schedule variable' do
+ success Entities::PipelineScheduleDetails
+ end
+ params do
+ requires :key, type: String, desc: 'The key of the variable'
+ end
+ delete ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do
+ authorize! :read_pipeline_schedule, user_project
+
+ not_found!('PipelineSchedule') unless pipeline_schedule
+ authorize! :admin_pipeline_schedule, pipeline_schedule
+
+ variable = pipeline_schedule.variables.find_by(key: params[:key])
+ not_found!('Variable') unless variable
+
+ status :accepted
+ present variable, with: Entities::Variable
+ end
+ end
end
helpers do