2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-10 09:32:23 -05:00
|
|
|
class PipelineSerializer < BaseSerializer
|
2017-09-04 12:04:33 -04:00
|
|
|
include WithPagination
|
2017-05-26 04:31:42 -04:00
|
|
|
entity PipelineDetailsEntity
|
2017-01-27 08:45:56 -05:00
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-12-07 09:22:01 -05:00
|
|
|
def represent(resource, opts = {})
|
2018-05-24 10:55:24 -04:00
|
|
|
if resource.is_a?(ActiveRecord::Relation)
|
2019-04-09 07:10:31 -04:00
|
|
|
resource = resource.preload(preloaded_relations)
|
2017-02-06 09:07:13 -05:00
|
|
|
end
|
|
|
|
|
2018-05-25 05:31:18 -04:00
|
|
|
if paginated?
|
|
|
|
resource = paginator.paginate(resource)
|
|
|
|
end
|
|
|
|
|
2018-05-23 07:29:21 -04:00
|
|
|
if opts.delete(:preload)
|
|
|
|
resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource)
|
2016-12-07 09:22:01 -05:00
|
|
|
end
|
2018-05-23 07:29:21 -04:00
|
|
|
|
|
|
|
super(resource, opts)
|
2016-12-07 09:22:01 -05:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-10 10:16:48 -05:00
|
|
|
|
|
|
|
def represent_status(resource)
|
2017-03-23 04:18:11 -04:00
|
|
|
return {} unless resource.present?
|
2017-03-23 06:37:27 -04:00
|
|
|
|
2017-03-10 10:16:48 -05:00
|
|
|
data = represent(resource, { only: [{ details: [:status] }] })
|
2017-03-21 08:15:20 -04:00
|
|
|
data.dig(:details, :status) || {}
|
2017-03-10 10:16:48 -05:00
|
|
|
end
|
2017-05-09 00:15:34 -04:00
|
|
|
|
|
|
|
def represent_stages(resource)
|
|
|
|
return {} unless resource.present?
|
|
|
|
|
2018-05-24 10:55:24 -04:00
|
|
|
data = represent(resource, { only: [{ details: [:stages] }], preload: true })
|
2017-05-09 00:15:34 -04:00
|
|
|
data.dig(:details, :stages) || []
|
|
|
|
end
|
2019-04-09 07:10:31 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def preloaded_relations
|
|
|
|
[
|
|
|
|
:cancelable_statuses,
|
2020-06-04 08:08:21 -04:00
|
|
|
:latest_statuses_ordered_by_stage,
|
2019-04-09 07:10:31 -04:00
|
|
|
:manual_actions,
|
2020-06-04 08:08:21 -04:00
|
|
|
:retryable_builds,
|
2019-04-09 07:10:31 -04:00
|
|
|
:scheduled_actions,
|
2020-06-04 08:08:21 -04:00
|
|
|
:stages,
|
|
|
|
:trigger_requests,
|
2019-12-24 10:07:44 -05:00
|
|
|
:user,
|
2020-03-09 08:07:45 -04:00
|
|
|
{
|
2020-06-04 08:08:21 -04:00
|
|
|
downloadable_artifacts: {
|
|
|
|
project: [:route, { namespace: :route }],
|
|
|
|
job: []
|
|
|
|
},
|
|
|
|
failed_builds: %i(project metadata),
|
2020-03-09 08:07:45 -04:00
|
|
|
merge_request: {
|
|
|
|
source_project: [:route, { namespace: :route }],
|
|
|
|
target_project: [:route, { namespace: :route }]
|
2020-06-04 08:08:21 -04:00
|
|
|
},
|
2019-04-09 07:10:31 -04:00
|
|
|
pending_builds: :project,
|
|
|
|
project: [:route, { namespace: :route }],
|
2020-06-04 08:08:21 -04:00
|
|
|
triggered_by_pipeline: [:project, :user],
|
|
|
|
triggered_pipelines: [:project, :user]
|
|
|
|
}
|
2019-04-09 07:10:31 -04:00
|
|
|
]
|
|
|
|
end
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|