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

61 lines
1.4 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)
2019-07-31 22:56:46 +05:30
resource = resource.preload(preloaded_relations)
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
2019-07-31 22:56:46 +05:30
private
def preloaded_relations
[
: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
2017-08-17 22:00:37 +05:30
end