2016-11-10 14:32:23 +00:00
|
|
|
class PipelineSerializer < BaseSerializer
|
2017-09-04 16:04:33 +00:00
|
|
|
include WithPagination
|
|
|
|
|
2017-03-01 11:00:37 +00:00
|
|
|
InvalidResourceError = Class.new(StandardError)
|
2016-12-07 14:22:01 +00:00
|
|
|
|
2017-05-26 08:31:42 +00:00
|
|
|
entity PipelineDetailsEntity
|
2017-01-27 13:45:56 +00:00
|
|
|
|
2016-12-07 14:22:01 +00:00
|
|
|
def represent(resource, opts = {})
|
2017-02-06 14:07:13 +00:00
|
|
|
if resource.is_a?(ActiveRecord::Relation)
|
2017-06-02 22:57:40 +00:00
|
|
|
|
2017-04-06 15:43:15 +00:00
|
|
|
resource = resource.preload([
|
2017-04-06 13:04:26 +00:00
|
|
|
:retryable_builds,
|
|
|
|
:cancelable_statuses,
|
2017-04-06 13:35:40 +00:00
|
|
|
:trigger_requests,
|
|
|
|
:project,
|
2017-06-02 22:57:40 +00:00
|
|
|
:manual_actions,
|
|
|
|
:artifacts,
|
|
|
|
{ pending_builds: :project }
|
2017-04-06 13:35:40 +00:00
|
|
|
])
|
2017-02-06 14:07:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if paginated?
|
2017-02-02 13:37:11 +00:00
|
|
|
super(@paginator.paginate(resource), opts)
|
2016-12-07 14:22:01 +00:00
|
|
|
else
|
|
|
|
super(resource, opts)
|
|
|
|
end
|
|
|
|
end
|
2017-03-10 15:16:48 +00:00
|
|
|
|
|
|
|
def represent_status(resource)
|
2017-03-23 08:18:11 +00:00
|
|
|
return {} unless resource.present?
|
2017-03-23 10:37:27 +00:00
|
|
|
|
2017-03-10 15:16:48 +00:00
|
|
|
data = represent(resource, { only: [{ details: [:status] }] })
|
2017-03-21 12:15:20 +00:00
|
|
|
data.dig(:details, :status) || {}
|
2017-03-10 15:16:48 +00:00
|
|
|
end
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
def represent_stages(resource)
|
|
|
|
return {} unless resource.present?
|
|
|
|
|
|
|
|
data = represent(resource, { only: [{ details: [:stages] }] })
|
|
|
|
data.dig(:details, :stages) || []
|
|
|
|
end
|
2016-11-10 14:32:23 +00:00
|
|
|
end
|