summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-17 22:58:23 +0900
committerShinya Maeda <gitlab.shinyamaeda@gmail.com>2017-05-30 23:55:09 +0900
commit17b9128b305aefc29fddae3b51d13c61ae7dfef9 (patch)
tree9b71d4f318daf6892b412b156fde1cf57f43dbf7
parentdf6040bbd41a639b3d0aa339b2dc0e84d67b811b (diff)
downloadgitlab-ce-17b9128b305aefc29fddae3b51d13c61ae7dfef9.tar.gz
includes last_pipeline
-rw-r--r--lib/api/entities.rb4
-rw-r--r--lib/api/pipeline_schedules.rb2
-rw-r--r--spec/requests/api/pipeline_schedules_spec.rb3
3 files changed, 5 insertions, 4 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 93f28e39f82..b2bc0a17142 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -690,9 +690,7 @@ module API
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 do |pipeline_schedule|
- pipeline_schedule.pipelines&.last
- end
+ expose :last_pipeline, using: Entities::Pipeline
expose :owner, using: Entities::UserBasic
end
diff --git a/lib/api/pipeline_schedules.rb b/lib/api/pipeline_schedules.rb
index 58888417888..27be796356c 100644
--- a/lib/api/pipeline_schedules.rb
+++ b/lib/api/pipeline_schedules.rb
@@ -17,7 +17,7 @@ module API
get ':id/pipeline_schedules' do
authorize! :read_pipeline_schedule, user_project
- pipeline_schedules = user_project.pipeline_schedules.preload(:pipelines)
+ pipeline_schedules = user_project.pipeline_schedules.includes(last_pipeline: {statuses: :latest})
present paginate(pipeline_schedules), with: Entities::PipelineSchedule
end
diff --git a/spec/requests/api/pipeline_schedules_spec.rb b/spec/requests/api/pipeline_schedules_spec.rb
index 34c4fcfcae1..1b44043907b 100644
--- a/spec/requests/api/pipeline_schedules_spec.rb
+++ b/spec/requests/api/pipeline_schedules_spec.rb
@@ -31,6 +31,9 @@ describe API::PipelineSchedules do
end.count
create_list(:ci_pipeline_schedule, 10, project: project, owner: developer)
+ .each do |pipeline_schedule|
+ pipeline_schedule.pipelines << build(:ci_pipeline, project: project)
+ end
expect do
get api("/projects/#{project.id}/pipeline_schedules", developer)