Commit 2178bd5f authored by Kamil Trzciński's avatar Kamil Trzciński

Fix stage.json endpoint

parent 551f8c4b
...@@ -106,7 +106,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -106,7 +106,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(@pipeline) .represent(@stage, details: true)
end end
def retry def retry
......
class StageDetailsEntity < Grape::Entity
include RequestAwareEntity
expose :name
expose :title do |stage|
"#{stage.name}: #{detailed_status.label}"
end
expose :statuses, with: JobEntity
expose :detailed_status, as: :status, with: StatusEntity
private
alias_method :stage, :object
def detailed_status
stage.detailed_status(request.current_user)
end
end
...@@ -11,6 +11,12 @@ class StageEntity < Grape::Entity ...@@ -11,6 +11,12 @@ class StageEntity < Grape::Entity
if: -> (_, opts) { opts[:grouped] }, if: -> (_, opts) { opts[:grouped] },
with: JobGroupEntity with: JobGroupEntity
expose :latest_statuses,
if: -> (_, opts) { opts[:details] },
with: JobEntity do |stage|
latest_statuses
end
expose :detailed_status, as: :status, with: StatusEntity expose :detailed_status, as: :status, with: StatusEntity
expose :path do |stage| expose :path do |stage|
...@@ -35,4 +41,14 @@ class StageEntity < Grape::Entity ...@@ -35,4 +41,14 @@ class StageEntity < Grape::Entity
def detailed_status def detailed_status
stage.detailed_status(request.current_user) stage.detailed_status(request.current_user)
end end
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
end end
...@@ -3,5 +3,5 @@ class StageSerializer < BaseSerializer ...@@ -3,5 +3,5 @@ class StageSerializer < BaseSerializer
InvalidResourceError = Class.new(StandardError) InvalidResourceError = Class.new(StandardError)
entity StageDetailsEntity entity StageEntity
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment