From 551f8c4b1a04fc0d2c8246fae5782a0c121ddfc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Mon, 23 Apr 2018 15:58:59 +0200 Subject: [PATCH] Add proper stage.json data --- .../projects/pipelines_controller.rb | 6 +++--- app/serializers/stage_details_entity.rb | 21 +++++++++++++++++++ app/serializers/stage_serializer.rb | 7 +++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 app/serializers/stage_details_entity.rb create mode 100644 app/serializers/stage_serializer.rb diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index 78d109cf33e..ef699e885b8 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -104,9 +104,9 @@ class Projects::PipelinesController < Projects::ApplicationController @stage = pipeline.legacy_stage(params[:stage]) return not_found unless @stage - respond_to do |format| - format.json { render json: { html: view_to_html_string('projects/pipelines/_stage') } } - end + render json: StageSerializer + .new(project: @project, current_user: @current_user) + .represent(@pipeline) end def retry diff --git a/app/serializers/stage_details_entity.rb b/app/serializers/stage_details_entity.rb new file mode 100644 index 00000000000..e9180d5fbb7 --- /dev/null +++ b/app/serializers/stage_details_entity.rb @@ -0,0 +1,21 @@ +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_serializer.rb b/app/serializers/stage_serializer.rb new file mode 100644 index 00000000000..19cb6c04c10 --- /dev/null +++ b/app/serializers/stage_serializer.rb @@ -0,0 +1,7 @@ +class StageSerializer < BaseSerializer + include WithPagination + + InvalidResourceError = Class.new(StandardError) + + entity StageDetailsEntity +end