summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/concerns/resolves_pipelines.rb
blob: 764ed9b15fd42331a182cc7fd62325ef61f17536 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

module ResolvesPipelines
  extend ActiveSupport::Concern

  included do
    type Types::Ci::PipelineType.connection_type, null: false
    argument :status,
             Types::Ci::PipelineStatusEnum,
             required: false,
             description: "Filter pipelines by their status."
    argument :scope, ::Types::Ci::PipelineScopeEnum,
             required: false,
             description: 'Filter pipelines by scope.'
    argument :ref,
             GraphQL::Types::String,
             required: false,
             description: "Filter pipelines by the ref they are run for."
    argument :sha,
             GraphQL::Types::String,
             required: false,
             description: "Filter pipelines by the sha of the commit they are run for."
    argument :source,
             GraphQL::Types::String,
             required: false,
             description: "Filter pipelines by their source."

    argument :updated_after, Types::TimeType,
             required: false,
             description: 'Pipelines updated after this date.'
    argument :updated_before, Types::TimeType,
             required: false,
             description: 'Pipelines updated before this date.'

    argument :username,
             GraphQL::Types::String,
             required: false,
             description: "Filter pipelines by the user that triggered the pipeline."
  end

  class_methods do
    def resolver_complexity(args, child_complexity:)
      complexity = super
      complexity += 2 if args[:sha]
      complexity += 2 if args[:ref]

      complexity
    end
  end

  def resolve_pipelines(project, params = {})
    Ci::PipelinesFinder.new(project, context[:current_user], params).execute
  end
end