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

78 lines
1.9 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,
2020-10-24 23:57:45 +05:30
:latest_builds_report_results,
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,
2021-01-03 14:25:43 +05:30
:latest_statuses,
2020-06-23 00:09:42 +05:30
: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-07-28 23:09:34 +05:30
triggered_by_pipeline: [{ project: [:route, { namespace: :route }] }, :user],
2021-01-03 14:25:43 +05:30
triggered_pipelines: [
{
project: [:route, { namespace: :route }]
},
:source_job,
:latest_statuses,
:user
]
2020-06-23 00:09:42 +05:30
}
2019-07-31 22:56:46 +05:30
]
end
2017-08-17 22:00:37 +05:30
end