gitlab-org--gitlab-foss/app/serializers/pipeline_serializer.rb

48 lines
1.1 KiB
Ruby
Raw Normal View History

class PipelineSerializer < BaseSerializer
InvalidResourceError = Class.new(StandardError)
entity PipelineEntity
def with_pagination(request, response)
tap { @paginator = Gitlab::Serializer::Pagination.new(request, response) }
end
def paginated?
@paginator.present?
end
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.preload([
2017-04-06 13:04:26 +00:00
:retryable_builds,
:cancelable_statuses,
2017-04-06 13:35:40 +00:00
:trigger_requests,
:project,
{ pending_builds: :project },
{ manual_actions: :project },
{ artifacts: :project }
])
end
if paginated?
super(@paginator.paginate(resource), opts)
else
super(resource, opts)
end
end
2017-03-10 15:16:48 +00:00
def represent_status(resource)
return {} unless resource.present?
2017-03-23 10:37:27 +00:00
2017-03-10 15:16:48 +00:00
data = represent(resource, { only: [{ details: [:status] }] })
2017-03-21 12:15:20 +00:00
data.dig(:details, :status) || {}
2017-03-10 15:16:48 +00:00
end
2017-05-09 04:15:34 +00:00
def represent_stages(resource)
return {} unless resource.present?
data = represent(resource, { only: [{ details: [:stages] }] })
data.dig(:details, :stages) || []
end
end