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

54 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class PipelineSerializer < BaseSerializer
2018-03-17 18:26:18 +05:30
include WithPagination
2017-09-10 17:25:29 +05:30
entity PipelineDetailsEntity
2017-08-17 22:00:37 +05:30
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.preload([
2018-11-08 19:23:39 +05:30
:stages,
2017-08-17 22:00:37 +05:30
:retryable_builds,
:cancelable_statuses,
:trigger_requests,
2017-09-10 17:25:29 +05:30
:manual_actions,
2018-12-05 23:21:45 +05:30
:scheduled_actions,
2017-09-10 17:25:29 +05:30
:artifacts,
2018-11-18 11:00:15 +05:30
{
pending_builds: :project,
project: [:route, { namespace: :route }],
artifacts: {
project: [:route, { namespace: :route }]
}
}
2017-08-17 22:00:37 +05:30
])
end
if paginated?
2018-11-08 19:23:39 +05:30
resource = paginator.paginate(resource)
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
if opts.delete(:preload)
resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource)
end
super(resource, opts)
2017-08-17 22:00:37 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-08-17 22:00:37 +05:30
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?
2018-11-08 19:23:39 +05:30
data = represent(resource, { only: [{ details: [:stages] }], preload: true })
2017-08-17 22:00:37 +05:30
data.dig(:details, :stages) || []
end
end