Merge branch '50461-add-retried-builds-in-pipeline-stage-endpoint' into 'master'
Add retried jobs to pipeline stages Closes #50461 See merge request gitlab-org/gitlab-ce!21558
This commit is contained in:
commit
cdc4cd09e7
|
@ -96,7 +96,7 @@ class Projects::PipelinesController < Projects::ApplicationController
|
||||||
|
|
||||||
render json: StageSerializer
|
render json: StageSerializer
|
||||||
.new(project: @project, current_user: @current_user)
|
.new(project: @project, current_user: @current_user)
|
||||||
.represent(@stage, details: true)
|
.represent(@stage, details: true, retried: params[:retried])
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: This endpoint is used by mini-pipeline-graph
|
# TODO: This endpoint is used by mini-pipeline-graph
|
||||||
|
|
|
@ -19,6 +19,12 @@ class StageEntity < Grape::Entity
|
||||||
latest_statuses
|
latest_statuses
|
||||||
end
|
end
|
||||||
|
|
||||||
|
expose :retried,
|
||||||
|
if: -> (_, opts) { opts[:retried] },
|
||||||
|
with: JobEntity do |stage|
|
||||||
|
retried_statuses
|
||||||
|
end
|
||||||
|
|
||||||
expose :detailed_status, as: :status, with: DetailedStatusEntity
|
expose :detailed_status, as: :status, with: DetailedStatusEntity
|
||||||
|
|
||||||
expose :path do |stage|
|
expose :path do |stage|
|
||||||
|
@ -48,9 +54,19 @@ class StageEntity < Grape::Entity
|
||||||
@grouped_statuses ||= stage.statuses.latest_ordered.group_by(&:status)
|
@grouped_statuses ||= stage.statuses.latest_ordered.group_by(&:status)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def grouped_retried_statuses
|
||||||
|
@grouped_retried_statuses ||= stage.statuses.retried_ordered.group_by(&:status)
|
||||||
|
end
|
||||||
|
|
||||||
def latest_statuses
|
def latest_statuses
|
||||||
HasStatus::ORDERED_STATUSES.map do |ordered_status|
|
HasStatus::ORDERED_STATUSES.map do |ordered_status|
|
||||||
grouped_statuses.fetch(ordered_status, [])
|
grouped_statuses.fetch(ordered_status, [])
|
||||||
end.flatten
|
end.flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def retried_statuses
|
||||||
|
HasStatus::ORDERED_STATUSES.map do |ordered_status|
|
||||||
|
grouped_retried_statuses.fetch(ordered_status, [])
|
||||||
|
end.flatten
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Add retried jobs to pipeline stage
|
||||||
|
merge_request: 21558
|
||||||
|
author:
|
||||||
|
type: other
|
|
@ -193,14 +193,34 @@ describe Projects::PipelinesController do
|
||||||
|
|
||||||
context 'when accessing existing stage' do
|
context 'when accessing existing stage' do
|
||||||
before do
|
before do
|
||||||
|
create(:ci_build, :retried, :failed, pipeline: pipeline, stage: 'build')
|
||||||
create(:ci_build, pipeline: pipeline, stage: 'build')
|
create(:ci_build, pipeline: pipeline, stage: 'build')
|
||||||
|
|
||||||
get_stage('build')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns html source for stage dropdown' do
|
context 'without retried' do
|
||||||
expect(response).to have_gitlab_http_status(:ok)
|
before do
|
||||||
expect(response).to match_response_schema('pipeline_stage')
|
get_stage('build')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns pipeline jobs without the retried builds' 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).not_to have_key('retried')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with retried' do
|
||||||
|
before do
|
||||||
|
get_stage('build', retried: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns pipelines jobs with the retried builds' 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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -214,12 +234,13 @@ describe Projects::PipelinesController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_stage(name)
|
def get_stage(name, params = {})
|
||||||
get :stage, namespace_id: project.namespace,
|
get :stage, **params.merge(
|
||||||
project_id: project,
|
namespace_id: project.namespace,
|
||||||
id: pipeline.id,
|
project_id: project,
|
||||||
stage: name,
|
id: pipeline.id,
|
||||||
format: :json
|
stage: name,
|
||||||
|
format: :json)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
"playable": { "type": "boolean" },
|
"playable": { "type": "boolean" },
|
||||||
"created_at": { "type": "string" },
|
"created_at": { "type": "string" },
|
||||||
"updated_at": { "type": "string" },
|
"updated_at": { "type": "string" },
|
||||||
"status": { "$ref": "../status/ci_detailed_status.json" }
|
"status": { "$ref": "../status/ci_detailed_status.json" },
|
||||||
|
"callout_message": { "type": "string" },
|
||||||
|
"recoverable": { "type": "boolean" }
|
||||||
},
|
},
|
||||||
"additionalProperties": true
|
"additionalProperties": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
"items": { "$ref": "job/job.json" },
|
"items": { "$ref": "job/job.json" },
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
"retried": {
|
||||||
|
"type": "array",
|
||||||
|
"items": { "$ref": "job/job.json" },
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
"status": { "$ref": "status/ci_detailed_status.json" },
|
"status": { "$ref": "status/ci_detailed_status.json" },
|
||||||
"path": { "type": "string" },
|
"path": { "type": "string" },
|
||||||
"dropdown_path": { "type": "string" }
|
"dropdown_path": { "type": "string" }
|
||||||
|
|
Loading…
Reference in New Issue