BigW Consortium Gitlab

pipeline_serializer.rb 947 Bytes
Newer Older
1
class PipelineSerializer < BaseSerializer
2
  InvalidResourceError = Class.new(StandardError)
3

4 5
  entity PipelineEntity

6
  def with_pagination(request, response)
7
    tap { @paginator = Gitlab::Serializer::Pagination.new(request, response) }
8 9 10
  end

  def paginated?
11
    @paginator.present?
12 13
  end

14
  def represent(resource, opts = {})
15
    if resource.is_a?(ActiveRecord::Relation)
16
      resource = resource.preload([
Kamil Trzcinski committed
17 18
        :retryable_builds,
        :cancelable_statuses,
Kamil Trzcinski committed
19 20 21 22 23 24
        :trigger_requests,
        :project,
        { pending_builds: :project },
        { manual_actions: :project },
        { artifacts: :project }
      ])
25 26 27
    end

    if paginated?
28
      super(@paginator.paginate(resource), opts)
29 30 31 32
    else
      super(resource, opts)
    end
  end
33 34

  def represent_status(resource)
35
    return {} unless resource.present?
36

37
    data = represent(resource, { only: [{ details: [:status] }] })
Shinya Maeda committed
38
    data.dig(:details, :status) || {}
39
  end
40
end