2018-07-19 18:43:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-21 13:51:53 +00:00
|
|
|
class StageEntity < Grape::Entity
|
2016-11-10 14:32:23 +00:00
|
|
|
include RequestAwareEntity
|
|
|
|
|
2016-12-09 20:56:12 +00:00
|
|
|
expose :name
|
2016-12-21 14:47:03 +00:00
|
|
|
|
2016-12-27 11:48:01 +00:00
|
|
|
expose :title do |stage|
|
|
|
|
"#{stage.name}: #{detailed_status.label}"
|
2016-12-15 14:59:18 +00:00
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
|
2017-05-06 16:45:46 +00:00
|
|
|
expose :groups,
|
|
|
|
if: -> (_, opts) { opts[:grouped] },
|
|
|
|
with: JobGroupEntity
|
|
|
|
|
2018-04-23 14:20:21 +00:00
|
|
|
expose :latest_statuses,
|
|
|
|
if: -> (_, opts) { opts[:details] },
|
2021-12-13 21:14:32 +00:00
|
|
|
with: Ci::JobEntity do |stage|
|
2018-04-23 14:20:21 +00:00
|
|
|
latest_statuses
|
|
|
|
end
|
|
|
|
|
2018-09-06 10:21:58 +00:00
|
|
|
expose :retried,
|
|
|
|
if: -> (_, opts) { opts[:retried] },
|
2021-12-13 21:14:32 +00:00
|
|
|
with: Ci::JobEntity do |stage|
|
2018-09-06 10:21:58 +00:00
|
|
|
retried_statuses
|
|
|
|
end
|
|
|
|
|
2018-09-11 17:13:24 +00:00
|
|
|
expose :detailed_status, as: :status, with: DetailedStatusEntity
|
2016-12-27 11:48:01 +00:00
|
|
|
|
2016-12-09 20:56:12 +00:00
|
|
|
expose :path do |stage|
|
2017-06-29 17:06:35 +00:00
|
|
|
project_pipeline_path(
|
2016-11-10 14:32:23 +00:00
|
|
|
stage.pipeline.project,
|
2016-12-27 11:48:01 +00:00
|
|
|
stage.pipeline,
|
2016-11-10 14:32:23 +00:00
|
|
|
anchor: stage.name)
|
|
|
|
end
|
2016-12-27 11:48:01 +00:00
|
|
|
|
|
|
|
expose :dropdown_path do |stage|
|
2017-06-29 17:06:35 +00:00
|
|
|
stage_project_pipeline_path(
|
2016-12-27 11:48:01 +00:00
|
|
|
stage.pipeline.project,
|
|
|
|
stage.pipeline,
|
|
|
|
stage: stage.name,
|
|
|
|
format: :json)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
alias_method :stage, :object
|
|
|
|
|
|
|
|
def detailed_status
|
2017-05-09 04:15:34 +00:00
|
|
|
stage.detailed_status(request.current_user)
|
2016-12-27 11:48:01 +00:00
|
|
|
end
|
2018-04-23 14:20:21 +00:00
|
|
|
|
|
|
|
def grouped_statuses
|
|
|
|
@grouped_statuses ||= stage.statuses.latest_ordered.group_by(&:status)
|
|
|
|
end
|
|
|
|
|
2018-09-06 10:21:58 +00:00
|
|
|
def grouped_retried_statuses
|
|
|
|
@grouped_retried_statuses ||= stage.statuses.retried_ordered.group_by(&:status)
|
|
|
|
end
|
|
|
|
|
2018-04-23 14:20:21 +00:00
|
|
|
def latest_statuses
|
2020-06-22 15:09:27 +00:00
|
|
|
Ci::HasStatus::ORDERED_STATUSES.flat_map do |ordered_status|
|
2018-04-23 14:20:21 +00:00
|
|
|
grouped_statuses.fetch(ordered_status, [])
|
2019-07-26 10:44:13 +00:00
|
|
|
end
|
2018-04-23 14:20:21 +00:00
|
|
|
end
|
2018-09-06 10:21:58 +00:00
|
|
|
|
|
|
|
def retried_statuses
|
2020-06-22 15:09:27 +00:00
|
|
|
Ci::HasStatus::ORDERED_STATUSES.flat_map do |ordered_status|
|
2018-09-06 10:21:58 +00:00
|
|
|
grouped_retried_statuses.fetch(ordered_status, [])
|
2019-07-26 10:44:13 +00:00
|
|
|
end
|
2018-09-06 10:21:58 +00:00
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|