debian-mirror-gitlab/app/serializers/pipeline_serializer.rb

43 lines
965 B
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
class PipelineSerializer < BaseSerializer
2018-03-17 18:26:18 +05:30
include WithPagination
2017-08-17 22:00:37 +05:30
InvalidResourceError = Class.new(StandardError)
2017-09-10 17:25:29 +05:30
entity PipelineDetailsEntity
2017-08-17 22:00:37 +05:30
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
resource = resource.preload([
:retryable_builds,
:cancelable_statuses,
:trigger_requests,
:project,
2017-09-10 17:25:29 +05:30
:manual_actions,
:artifacts,
{ pending_builds: :project }
2017-08-17 22:00:37 +05:30
])
end
if paginated?
super(@paginator.paginate(resource), opts)
else
super(resource, opts)
end
end
def represent_status(resource)
return {} unless resource.present?
data = represent(resource, { only: [{ details: [:status] }] })
data.dig(:details, :status) || {}
end
def represent_stages(resource)
return {} unless resource.present?
data = represent(resource, { only: [{ details: [:stages] }] })
data.dig(:details, :stages) || []
end
end