summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Azzopardi <steveazz@outlook.com>2018-10-01 13:17:09 +0200
committerSteve Azzopardi <steveazz@outlook.com>2018-10-01 13:26:02 +0200
commite8e27d5d27d852b2f44cec0c40320d6ee93d6e9d (patch)
treef8219f30d9700c2a29152d5004183913fec21446
parent2155ba8b402391d17426dae531d5d85f3f433d2a (diff)
downloadgitlab-ce-52043-job-api-keep-order-of-jobs-in-stage-dropdown.tar.gz
Add ordered_statues to pipelines/:id/stages52043-job-api-keep-order-of-jobs-in-stage-dropdown
When the query parameter `ordered_statuses` is set in the `pipelines/:id/stages` endpoint, a new property will be sent with the key `ordered_statues` this will return all the builds that stage has, in an ordered state. This includes the ones from `latest_statues` as well. closes https://gitlab.com/gitlab-org/gitlab-ce/issues/52043
-rw-r--r--app/controllers/projects/pipelines_controller.rb7
-rw-r--r--app/serializers/stage_entity.rb16
-rw-r--r--changelogs/unreleased/52043-job-api-keep-order-of-jobs-in-stage-dropdown.yml5
-rw-r--r--spec/controllers/projects/pipelines_controller_spec.rb24
-rw-r--r--spec/fixtures/api/schemas/pipeline_stage.json5
5 files changed, 53 insertions, 4 deletions
diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb
index 53b29d4146e..1501de53705 100644
--- a/app/controllers/projects/pipelines_controller.rb
+++ b/app/controllers/projects/pipelines_controller.rb
@@ -98,7 +98,12 @@ class Projects::PipelinesController < Projects::ApplicationController
render json: StageSerializer
.new(project: @project, current_user: @current_user)
- .represent(@stage, details: true, retried: params[:retried])
+ .represent(
+ @stage,
+ details: true,
+ retried: params[:retried],
+ ordered_statuses: params[:ordered_statuses]
+ )
end
# TODO: This endpoint is used by mini-pipeline-graph
diff --git a/app/serializers/stage_entity.rb b/app/serializers/stage_entity.rb
index 029dd3d0684..8083a102e67 100644
--- a/app/serializers/stage_entity.rb
+++ b/app/serializers/stage_entity.rb
@@ -25,6 +25,12 @@ class StageEntity < Grape::Entity
retried_statuses
end
+ expose :ordered_statuses,
+ if: -> (_, opts) { opts[:ordered_statuses] },
+ with: JobEntity do |stage|
+ ordered_statuses
+ end
+
expose :detailed_status, as: :status, with: DetailedStatusEntity
expose :path do |stage|
@@ -58,6 +64,10 @@ class StageEntity < Grape::Entity
@grouped_retried_statuses ||= stage.statuses.retried_ordered.group_by(&:status)
end
+ def statuses
+ @statuses ||= stage.statuses.group_by(&:status)
+ end
+
def latest_statuses
HasStatus::ORDERED_STATUSES.map do |ordered_status|
grouped_statuses.fetch(ordered_status, [])
@@ -69,4 +79,10 @@ class StageEntity < Grape::Entity
grouped_retried_statuses.fetch(ordered_status, [])
end.flatten
end
+
+ def ordered_statuses
+ HasStatus::ORDERED_STATUSES.map do |ordered_status|
+ statuses.fetch(ordered_status, [])
+ end.flatten
+ end
end
diff --git a/changelogs/unreleased/52043-job-api-keep-order-of-jobs-in-stage-dropdown.yml b/changelogs/unreleased/52043-job-api-keep-order-of-jobs-in-stage-dropdown.yml
new file mode 100644
index 00000000000..6ca860f6e36
--- /dev/null
+++ b/changelogs/unreleased/52043-job-api-keep-order-of-jobs-in-stage-dropdown.yml
@@ -0,0 +1,5 @@
+---
+title: Add oredered_statues to pipeline/:id/stage API
+merge_request: 22020
+author:
+type: other
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb
index 5c7415a318d..05a75b90ae4 100644
--- a/spec/controllers/projects/pipelines_controller_spec.rb
+++ b/spec/controllers/projects/pipelines_controller_spec.rb
@@ -199,10 +199,11 @@ describe Projects::PipelinesController do
context 'when accessing existing stage' do
before do
create(:ci_build, :retried, :failed, pipeline: pipeline, stage: 'build')
- create(:ci_build, pipeline: pipeline, stage: 'build')
+ create(:ci_build, :retried, :canceled, pipeline: pipeline, stage: 'build')
+ create(:ci_build, :success, pipeline: pipeline, stage: 'build')
end
- context 'without retried' do
+ context 'without retried or ordered_statues' do
before do
get_stage('build')
end
@@ -212,6 +213,7 @@ describe Projects::PipelinesController do
expect(response).to match_response_schema('pipeline_stage')
expect(json_response['latest_statuses'].length).to eq 1
expect(json_response).not_to have_key('retried')
+ expect(json_response).not_to have_key('ordered_statues')
end
end
@@ -224,7 +226,23 @@ describe Projects::PipelinesController do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('pipeline_stage')
expect(json_response['latest_statuses'].length).to eq 1
- expect(json_response['retried'].length).to eq 1
+ expect(json_response['retried'].length).to eq 2
+ end
+ end
+
+ context 'with ordered_statues' do
+ before do
+ get_stage('build', ordered_statuses: true)
+ end
+
+ it 'returns pipelines with all jobs in ordered form' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('pipeline_stage')
+ expect(json_response['latest_statuses'].length).to eq 1
+ expect(json_response['ordered_statuses'].length).to eq 3
+ expect(json_response['ordered_statuses'][0]['status']['group']).to eq 'failed'
+ expect(json_response['ordered_statuses'][1]['status']['group']).to eq 'canceled'
+ expect(json_response['ordered_statuses'][2]['status']['group']).to eq 'success'
end
end
end
diff --git a/spec/fixtures/api/schemas/pipeline_stage.json b/spec/fixtures/api/schemas/pipeline_stage.json
index c01a1946185..2fefa57583a 100644
--- a/spec/fixtures/api/schemas/pipeline_stage.json
+++ b/spec/fixtures/api/schemas/pipeline_stage.json
@@ -21,6 +21,11 @@
"items": { "$ref": "job/job.json" },
"optional": true
},
+ "ordered_statuses": {
+ "type": "array",
+ "items": { "$ref": "job/job.json" },
+ "optional": true
+ },
"status": { "$ref": "status/ci_detailed_status.json" },
"path": { "type": "string" },
"dropdown_path": { "type": "string" }