summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-04-23 15:58:59 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2018-04-23 15:58:59 +0200
commit551f8c4b1a04fc0d2c8246fae5782a0c121ddfc0 (patch)
treeef2ef18e92b45c11809c5890255cd5cc6a15303e
parente0b7541b9aa1f107d024803e96e8dda9b9fb7978 (diff)
downloadgitlab-ce-551f8c4b1a04fc0d2c8246fae5782a0c121ddfc0.tar.gz
Add proper stage.json data
-rw-r--r--app/controllers/projects/pipelines_controller.rb6
-rw-r--r--app/serializers/stage_details_entity.rb21
-rw-r--r--app/serializers/stage_serializer.rb7
3 files changed, 31 insertions, 3 deletions
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