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] },
|
|
|
|
with: JobEntity do |stage|
|
|
|
|
latest_statuses
|
|
|
|
end
|
|
|
|
|
2017-05-06 16:45:46 +00:00
|
|
|
expose :detailed_status, as: :status, with: StatusEntity
|
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
|
|
|
|
|
|
|
|
def latest_statuses
|
|
|
|
HasStatus::ORDERED_STATUSES.map do |ordered_status|
|
|
|
|
grouped_statuses.fetch(ordered_status, [])
|
|
|
|
end.flatten
|
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|