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

daily_build_group_report_results_finder.rb « ci « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef97ccb4c0f6d440e0c7bc807172b309345fd46e (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
55
56
# frozen_string_literal: true

module Ci
  class DailyBuildGroupReportResultsFinder
    include Gitlab::Allowable

    def initialize(current_user:, project:, ref_path: nil, start_date:, end_date:, limit: nil)
      @current_user = current_user
      @project = project
      @ref_path = ref_path
      @start_date = start_date
      @end_date = end_date
      @limit = limit
    end

    def execute
      return none unless query_allowed?

      query
    end

    protected

    attr_reader :current_user, :project, :ref_path, :start_date, :end_date, :limit

    def query
      Ci::DailyBuildGroupReportResult.recent_results(
        query_params,
        limit: limit
      )
    end

    def query_allowed?
      can?(current_user, :read_build_report_results, project)
    end

    def query_params
      params = {
        project_id: project,
        date: start_date..end_date
      }

      if ref_path.present?
        params[:ref_path] = ref_path
      else
        params[:default_branch] = true
      end

      params
    end

    def none
      Ci::DailyBuildGroupReportResult.none
    end
  end
end