2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class DailyBuildGroupReportResultsFinder
|
|
|
|
include Gitlab::Allowable
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def initialize(current_user:, project:, ref_path: nil, start_date:, end_date:, limit: nil)
|
2020-05-24 23:13:21 +05:30
|
|
|
@current_user = current_user
|
|
|
|
@project = project
|
|
|
|
@ref_path = ref_path
|
|
|
|
@start_date = start_date
|
|
|
|
@end_date = end_date
|
|
|
|
@limit = limit
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2020-10-24 23:57:45 +05:30
|
|
|
return none unless query_allowed?
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
query
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
attr_reader :current_user, :project, :ref_path, :start_date, :end_date, :limit
|
|
|
|
|
|
|
|
def query
|
2020-05-24 23:13:21 +05:30
|
|
|
Ci::DailyBuildGroupReportResult.recent_results(
|
2020-06-23 00:09:42 +05:30
|
|
|
query_params,
|
|
|
|
limit: limit
|
2020-05-24 23:13:21 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def query_allowed?
|
|
|
|
can?(current_user, :read_build_report_results, project)
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
def query_params
|
2021-02-22 17:27:13 +05:30
|
|
|
params = {
|
2020-06-23 00:09:42 +05:30
|
|
|
project_id: project,
|
|
|
|
date: start_date..end_date
|
|
|
|
}
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
if ref_path.present?
|
|
|
|
params[:ref_path] = ref_path
|
|
|
|
else
|
|
|
|
params[:default_branch] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
params
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
def none
|
|
|
|
Ci::DailyBuildGroupReportResult.none
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|