Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pipeline_scope_counts.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02f4ea33ddf4408108079464d8785da19a7593e1 (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
# frozen_string_literal: true

module Gitlab
  class PipelineScopeCounts
    attr_reader :project

    PIPELINES_COUNT_LIMIT = 1000

    def self.declarative_policy_class
      'Ci::ProjectPipelinesPolicy'
    end

    def initialize(current_user, project, params)
      @current_user = current_user
      @project = project
      @params = params
    end

    def all
      finder.execute.limit(PIPELINES_COUNT_LIMIT).count
    end

    def running
      finder({ scope: "running" }).execute.limit(PIPELINES_COUNT_LIMIT).count
    end

    def finished
      finder({ scope: "finished" }).execute.limit(PIPELINES_COUNT_LIMIT).count
    end

    def pending
      finder({ scope: "pending" }).execute.limit(PIPELINES_COUNT_LIMIT).count
    end

    private

    def finder(params = {})
      ::Ci::PipelinesFinder.new(@project, @current_user, @params.merge(params))
    end
  end
end