stage_entity.rb 831 Bytes
Newer Older
1
class StageEntity < Grape::Entity
Kamil Trzciński's avatar
Kamil Trzciński committed
2 3
  include RequestAwareEntity

4
  expose :name
5

6 7
  expose :title do |stage|
    "#{stage.name}: #{detailed_status.label}"
8
  end
Kamil Trzciński's avatar
Kamil Trzciński committed
9

10 11 12 13 14
  expose :groups,
    if: -> (_, opts) { opts[:grouped] },
    with: JobGroupEntity

  expose :detailed_status, as: :status, with: StatusEntity
15

16
  expose :path do |stage|
Kamil Trzciński's avatar
Kamil Trzciński committed
17 18 19
    namespace_project_pipeline_path(
      stage.pipeline.project.namespace,
      stage.pipeline.project,
20
      stage.pipeline,
Kamil Trzciński's avatar
Kamil Trzciński committed
21 22
      anchor: stage.name)
  end
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

  expose :dropdown_path do |stage|
    stage_namespace_project_pipeline_path(
      stage.pipeline.project.namespace,
      stage.pipeline.project,
      stage.pipeline,
      stage: stage.name,
      format: :json)
  end

  private

  alias_method :stage, :object

  def detailed_status
    stage.detailed_status(request.user)
  end
Kamil Trzciński's avatar
Kamil Trzciński committed
40
end