summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-27 22:22:33 +0900
committerShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-30 23:55:09 +0900
commit63ca126e977666335d7e5f70665815d1289a6f34 (patch)
tree17fe03f66ba740d4497bab2f8fb1a2c31580512a
parentb17c8d67d8811e0a440338dc25464d8c90e81179 (diff)
downloadgitlab-ce-63ca126e977666335d7e5f70665815d1289a6f34.tar.gz
Improve API with optinal and default. Allow to use scope as a parameter.
-rw-r--r--lib/api/pipeline_schedules.rb10
-rw-r--r--spec/requests/api/pipeline_schedules_spec.rb18
2 files changed, 25 insertions, 3 deletions
diff --git a/lib/api/pipeline_schedules.rb b/lib/api/pipeline_schedules.rb
index 5269239b7ed..52ad682b972 100644
--- a/lib/api/pipeline_schedules.rb
+++ b/lib/api/pipeline_schedules.rb
@@ -13,11 +13,15 @@ module API
end
params do
use :pagination
+ optional :scope, type: String, values: %w[active inactive],
+ desc: 'The scope of pipeline schedules'
end
get ':id/pipeline_schedules' do
authorize! :read_pipeline_schedule, user_project
- present paginate(pipeline_schedules), with: Entities::PipelineSchedule
+ schedules = PipelineSchedulesFinder.new(user_project).execute(scope: params[:scope])
+ .preload([:owner, :last_pipeline])
+ present paginate(schedules), with: Entities::PipelineSchedule
end
desc 'Get a single pipeline schedule' do
@@ -41,8 +45,8 @@ module API
requires :description, type: String, desc: 'The description of pipeline schedule'
requires :ref, type: String, desc: 'The branch/tag name will be triggered'
requires :cron, type: String, desc: 'The cron'
- requires :cron_timezone, type: String, desc: 'The timezone'
- requires :active, type: Boolean, desc: 'The activation of pipeline schedule'
+ optional :cron_timezone, type: String, default: 'UTC', desc: 'The timezone'
+ optional :active, type: Boolean, default: true, desc: 'The activation of pipeline schedule'
end
post ':id/pipeline_schedules' do
authorize! :create_pipeline_schedule, user_project
diff --git a/spec/requests/api/pipeline_schedules_spec.rb b/spec/requests/api/pipeline_schedules_spec.rb
index 74de2f0ba4a..77bf377884d 100644
--- a/spec/requests/api/pipeline_schedules_spec.rb
+++ b/spec/requests/api/pipeline_schedules_spec.rb
@@ -43,6 +43,24 @@ describe API::PipelineSchedules do
get api("/projects/#{project.id}/pipeline_schedules", developer)
end.not_to exceed_query_limit(control_count)
end
+
+ %w[active inactive].each do |target|
+ context "when scope is #{target}" do
+ before do
+ create(:ci_pipeline_schedule, project: project, active: active?(target))
+ end
+
+ it 'returns matched pipeline schedules' do
+ get api("/projects/#{project.id}/pipeline_schedules", developer), scope: target
+
+ expect(json_response.map{ |r| r['active'] }).to all(eq(active?(target)))
+ end
+ end
+
+ def active?(str)
+ (str == 'active') ? true : false
+ end
+ end
end
context 'authenticated user with invalid permissions' do