summaryrefslogtreecommitdiff
path: root/app/serializers
diff options
context:
space:
mode:
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/build_entity.rb14
-rw-r--r--app/serializers/build_serializer.rb12
-rw-r--r--app/serializers/pipeline_entity.rb12
-rw-r--r--app/serializers/pipeline_serializer.rb8
4 files changed, 37 insertions, 9 deletions
diff --git a/app/serializers/build_entity.rb b/app/serializers/build_entity.rb
index 531b3768da3..10151d94e68 100644
--- a/app/serializers/build_entity.rb
+++ b/app/serializers/build_entity.rb
@@ -19,15 +19,21 @@ class BuildEntity < Grape::Entity
expose :created_at
expose :updated_at
- expose :status do |build, options|
- StatusEntity.represent(
- build.detailed_status(request.user),
- options)
+ expose :details do
+ expose :detailed_status,
+ as: :status,
+ with: StatusEntity
end
private
+ alias_method :build, :object
+
def path_to(route, build)
send("#{route}_path", build.project.namespace, build.project, build)
end
+
+ def detailed_status
+ build.detailed_status(request.user)
+ end
end
diff --git a/app/serializers/build_serializer.rb b/app/serializers/build_serializer.rb
index 637aacc7be5..39460bbd092 100644
--- a/app/serializers/build_serializer.rb
+++ b/app/serializers/build_serializer.rb
@@ -1,3 +1,15 @@
class BuildSerializer < BaseSerializer
entity BuildEntity
+
+ def with_status
+ tap { @status_only = {only: [{details: [:status]}]} }
+ end
+
+ def represent(resource, opts = {})
+ if @status_only.present?
+ opts.merge!(@status_only)
+ end
+
+ super(resource, opts)
+ end
end
diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb
index 61f0f11d7d2..1c1fa9e3dee 100644
--- a/app/serializers/pipeline_entity.rb
+++ b/app/serializers/pipeline_entity.rb
@@ -12,11 +12,9 @@ class PipelineEntity < Grape::Entity
end
expose :details do
- expose :status do |pipeline, options|
- StatusEntity.represent(
- pipeline.detailed_status(request.user),
- options)
- end
+ expose :detailed_status,
+ as: :status,
+ with: StatusEntity
expose :duration
expose :finished_at
@@ -82,4 +80,8 @@ class PipelineEntity < Grape::Entity
pipeline.cancelable? &&
can?(request.user, :update_pipeline, pipeline)
end
+
+ def detailed_status
+ pipeline.detailed_status(request.user)
+ end
end
diff --git a/app/serializers/pipeline_serializer.rb b/app/serializers/pipeline_serializer.rb
index ab2d3d5a3ec..4de9e620f64 100644
--- a/app/serializers/pipeline_serializer.rb
+++ b/app/serializers/pipeline_serializer.rb
@@ -11,11 +11,19 @@ class PipelineSerializer < BaseSerializer
@paginator.present?
end
+ def with_status
+ tap { @status_only = {only: [{details: [:status]}]} }
+ end
+
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.includes(project: :namespace)
end
+ if @status_only.present?
+ opts.merge!(@status_only)
+ end
+
if paginated?
super(@paginator.paginate(resource), opts)
else