summaryrefslogtreecommitdiff
path: root/app/serializers/pipeline_serializer.rb
blob: 68325cbffa87c6848cd1e4660dea072e0c5e3b5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class PipelineSerializer < BaseSerializer
  include WithPagination
  entity PipelineDetailsEntity

  def represent(resource, opts = {})
    if resource.is_a?(ActiveRecord::Relation)

      resource = resource.preload([
        :stages,
        :retryable_builds,
        :cancelable_statuses,
        :trigger_requests,
        :project,
        :manual_actions,
        :artifacts,
        { pending_builds: :project }
      ])
    end

    if opts.delete(:preload)
      resource = @paginator.paginate(resource) if paginated?
      resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource)
    end

    super(resource, opts)
  end

  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?

    data = represent(resource, { only: [{ details: [:stages] }] })
    data.dig(:details, :stages) || []
  end
end