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

69 lines
1.7 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
[
:cancelable_statuses,
2020-06-23 00:09:42 +05:30
:latest_statuses_ordered_by_stage,
2019-07-31 22:56:46 +05:30
:manual_actions,
2020-06-23 00:09:42 +05:30
:retryable_builds,
2019-07-31 22:56:46 +05:30
:scheduled_actions,
2020-06-23 00:09:42 +05:30
:stages,
:trigger_requests,
2020-01-01 13:55:28 +05:30
:user,
2020-04-08 14:13:33 +05:30
{
2020-06-23 00:09:42 +05:30
downloadable_artifacts: {
project: [:route, { namespace: :route }],
job: []
},
failed_builds: %i(project metadata),
2020-04-08 14:13:33 +05:30
merge_request: {
source_project: [:route, { namespace: :route }],
target_project: [:route, { namespace: :route }]
2020-06-23 00:09:42 +05:30
},
2019-07-31 22:56:46 +05:30
pending_builds: :project,
project: [:route, { namespace: :route }],
2020-06-23 00:09:42 +05:30
triggered_by_pipeline: [:project, :user],
triggered_pipelines: [:project, :user]
}
2019-07-31 22:56:46 +05:30
]
end
2017-08-17 22:00:37 +05:30
end