gitlab-org--gitlab-foss/app/serializers/pipeline_serializer.rb
Shinya Maeda 50776d2d29 Expose merge request entity for pipelines
Add preload

Fix

ok

Write tests

test only postgresql

ok

add more test
;

Improve wording

Add changelog

Fix
2019-03-06 16:30:35 +07:00

54 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class PipelineSerializer < BaseSerializer
include WithPagination
entity PipelineDetailsEntity
# rubocop: disable CodeReuse/ActiveRecord
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.preload([
:stages,
:retryable_builds,
:cancelable_statuses,
:trigger_requests,
:manual_actions,
:scheduled_actions,
:artifacts,
:merge_request,
{
pending_builds: :project,
project: [:route, { namespace: :route }],
artifacts: {
project: [:route, { namespace: :route }]
}
}
])
end
if paginated?
resource = paginator.paginate(resource)
end
if opts.delete(:preload)
resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource)
end
super(resource, opts)
end
# rubocop: enable CodeReuse/ActiveRecord
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] }], preload: true })
data.dig(:details, :stages) || []
end
end