2016-11-10 09:32:23 -05:00
|
|
|
class PipelineSerializer < BaseSerializer
|
2017-03-01 06:00:37 -05:00
|
|
|
InvalidResourceError = Class.new(StandardError)
|
2016-12-07 09:22:01 -05:00
|
|
|
|
2017-05-26 04:31:42 -04:00
|
|
|
entity PipelineDetailsEntity
|
2017-01-27 08:45:56 -05:00
|
|
|
|
2017-02-02 08:37:11 -05:00
|
|
|
def with_pagination(request, response)
|
2017-02-06 08:47:56 -05:00
|
|
|
tap { @paginator = Gitlab::Serializer::Pagination.new(request, response) }
|
2017-02-02 08:37:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def paginated?
|
2017-02-07 07:13:33 -05:00
|
|
|
@paginator.present?
|
2017-02-02 08:37:11 -05:00
|
|
|
end
|
|
|
|
|
2016-12-07 09:22:01 -05:00
|
|
|
def represent(resource, opts = {})
|
2017-02-06 09:07:13 -05:00
|
|
|
if resource.is_a?(ActiveRecord::Relation)
|
2017-06-02 18:57:40 -04:00
|
|
|
|
2017-04-06 11:43:15 -04:00
|
|
|
resource = resource.preload([
|
2017-04-06 09:04:26 -04:00
|
|
|
:retryable_builds,
|
|
|
|
:cancelable_statuses,
|
2017-04-06 09:35:40 -04:00
|
|
|
:trigger_requests,
|
|
|
|
:project,
|
2017-06-02 18:57:40 -04:00
|
|
|
:manual_actions,
|
|
|
|
:artifacts,
|
|
|
|
{ pending_builds: :project }
|
2017-04-06 09:35:40 -04:00
|
|
|
])
|
2017-02-06 09:07:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if paginated?
|
2017-02-02 08:37:11 -05:00
|
|
|
super(@paginator.paginate(resource), opts)
|
2016-12-07 09:22:01 -05:00
|
|
|
else
|
|
|
|
super(resource, opts)
|
|
|
|
end
|
|
|
|
end
|
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?
|
|
|
|
|
|
|
|
data = represent(resource, { only: [{ details: [:stages] }] })
|
|
|
|
data.dig(:details, :stages) || []
|
|
|
|
end
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|