summaryrefslogtreecommitdiff
path: root/lib/gitlab/graphql/loaders/pipeline_for_sha_loader.rb
blob: 81c5cabf45124235244602aecbeaf5301a8d13ff (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
# frozen_string_literal: true

module Gitlab
  module Graphql
    module Loaders
      class PipelineForShaLoader
        attr_accessor :project, :sha

        def initialize(project, sha)
          @project, @sha = project, sha
        end

        def find_last
          BatchLoader.for(sha).batch(key: project) do |shas, loader, args|
            pipelines = args[:key].ci_pipelines.latest_for_shas(shas)

            pipelines.each do |pipeline|
              loader.call(pipeline.sha, pipeline)
            end
          end
        end
      end
    end
  end
end