diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-04-23 16:20:21 +0200 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-04-23 16:20:21 +0200 |
commit | 2178bd5ff408a9a16549b90a6e1987afa32527b9 (patch) | |
tree | 5fffcd0c46df88e71d58df3103a1a22efda3b93f /app/serializers | |
parent | 551f8c4b1a04fc0d2c8246fae5782a0c121ddfc0 (diff) | |
download | gitlab-ce-2178bd5ff408a9a16549b90a6e1987afa32527b9.tar.gz |
Fix stage.json endpoint
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/stage_details_entity.rb | 21 | ||||
-rw-r--r-- | app/serializers/stage_entity.rb | 16 | ||||
-rw-r--r-- | app/serializers/stage_serializer.rb | 2 |
3 files changed, 17 insertions, 22 deletions
diff --git a/app/serializers/stage_details_entity.rb b/app/serializers/stage_details_entity.rb deleted file mode 100644 index e9180d5fbb7..00000000000 --- a/app/serializers/stage_details_entity.rb +++ /dev/null @@ -1,21 +0,0 @@ -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 diff --git a/app/serializers/stage_entity.rb b/app/serializers/stage_entity.rb index 4523b15152e..2516df70ad9 100644 --- a/app/serializers/stage_entity.rb +++ b/app/serializers/stage_entity.rb @@ -11,6 +11,12 @@ class StageEntity < Grape::Entity if: -> (_, opts) { opts[:grouped] }, with: JobGroupEntity + expose :latest_statuses, + if: -> (_, opts) { opts[:details] }, + with: JobEntity do |stage| + latest_statuses + end + expose :detailed_status, as: :status, with: StatusEntity expose :path do |stage| @@ -35,4 +41,14 @@ class StageEntity < Grape::Entity def detailed_status stage.detailed_status(request.current_user) 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 diff --git a/app/serializers/stage_serializer.rb b/app/serializers/stage_serializer.rb index 19cb6c04c10..091d8e91e43 100644 --- a/app/serializers/stage_serializer.rb +++ b/app/serializers/stage_serializer.rb @@ -3,5 +3,5 @@ class StageSerializer < BaseSerializer InvalidResourceError = Class.new(StandardError) - entity StageDetailsEntity + entity StageEntity end |