diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-27 21:14:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-27 21:14:37 +0300 |
commit | 956c34e4688544cba1ceee3205242df3b3a9fe30 (patch) | |
tree | be677c3ef09d2b2348c4ef6adcfb79092ad37b5e /lib/gitlab/pipeline_scope_counts.rb | |
parent | 48f93eadd0c117a41b4e29e3d335f451a5e6e52f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/pipeline_scope_counts.rb')
-rw-r--r-- | lib/gitlab/pipeline_scope_counts.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/gitlab/pipeline_scope_counts.rb b/lib/gitlab/pipeline_scope_counts.rb new file mode 100644 index 00000000000..02f4ea33ddf --- /dev/null +++ b/lib/gitlab/pipeline_scope_counts.rb @@ -0,0 +1,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 |