Class: Ci::JobAnalytics::QueryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ci/job_analytics/query_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, current_user:, options: {}) ⇒ QueryBuilder

Returns a new instance of QueryBuilder.

Parameters:

  • project (Project)

    The project to find jobs for

  • options (Hash) (defaults to: {})

    options for filtering and configuring the query builder

Options Hash (options:):

  • :select_fields (Array)

    Fields to select

  • :aggregations (Array)

    Aggregations to perform

  • :sort (String)

    Sort order (ex. rate_of_success_asc)

  • :source (String)

    Pipeline source

  • :ref (String)

    Git reference

  • :from_time (Time)

    Start time for filtering (defaults to 7 days ago)

  • :to_time (Time)

    End time for filtering

  • :name_search (String)

    Search by name of the pipeline jobs.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ci/job_analytics/query_builder.rb', line 19

def initialize(project:, current_user:, options: {})
  @project = project
  @current_user = current_user
  @select_fields = options[:select_fields] || []
  @aggregations = options[:aggregations] || []
  @sort = options[:sort]
  @source = options[:source]
  @ref = options[:ref]
  @from_time = options[:from_time] || 1.week.ago.utc
  @to_time = options[:to_time]
  @name_search = options[:name_search]
end

Instance Attribute Details

#aggregationsObject (readonly)

Returns the value of attribute aggregations.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def aggregations
  @aggregations
end

#current_userObject (readonly)

Returns the value of attribute current_user.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def current_user
  @current_user
end

#from_timeObject (readonly)

Returns the value of attribute from_time.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def from_time
  @from_time
end

#name_searchObject (readonly)

Returns the value of attribute name_search.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def name_search
  @name_search
end

#projectObject (readonly)

Returns the value of attribute project.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def project
  @project
end

#refObject (readonly)

Returns the value of attribute ref.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def ref
  @ref
end

#select_fieldsObject (readonly)

Returns the value of attribute select_fields.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def select_fields
  @select_fields
end

#sortObject (readonly)

Returns the value of attribute sort.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def sort
  @sort
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def source
  @source
end

#to_timeObject (readonly)

Returns the value of attribute to_time.



6
7
8
# File 'lib/ci/job_analytics/query_builder.rb', line 6

def to_time
  @to_time
end

Instance Method Details

#executeObject



32
33
34
35
36
37
# File 'lib/ci/job_analytics/query_builder.rb', line 32

def execute
  return unless ::Gitlab::ClickHouse.enabled_for_analytics? && Ability.allowed?(current_user, :read_build,
    project)

  build_finder.query_builder
end