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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/projects/ci/daily_build_group_report_results_controller.rb')
-rw-r--r--app/controllers/projects/ci/daily_build_group_report_results_controller.rb77
1 files changed, 77 insertions, 0 deletions
diff --git a/app/controllers/projects/ci/daily_build_group_report_results_controller.rb b/app/controllers/projects/ci/daily_build_group_report_results_controller.rb
new file mode 100644
index 00000000000..dfda5fca310
--- /dev/null
+++ b/app/controllers/projects/ci/daily_build_group_report_results_controller.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+class Projects::Ci::DailyBuildGroupReportResultsController < Projects::ApplicationController
+ include Gitlab::Utils::StrongMemoize
+
+ MAX_ITEMS = 1000
+ REPORT_WINDOW = 90.days
+
+ before_action :validate_feature_flag!
+ before_action :authorize_download_code! # Share the same authorization rules as the graphs controller
+ before_action :validate_param_type!
+
+ def index
+ respond_to do |format|
+ format.csv { send_data(render_csv(results), type: 'text/csv; charset=utf-8') }
+ end
+ end
+
+ private
+
+ def validate_feature_flag!
+ render_404 unless Feature.enabled?(:ci_download_daily_code_coverage, project, default_enabled: true)
+ end
+
+ def validate_param_type!
+ respond_422 unless allowed_param_types.include?(param_type)
+ end
+
+ def render_csv(collection)
+ CsvBuilders::SingleBatch.new(
+ collection,
+ {
+ date: 'date',
+ group_name: 'group_name',
+ param_type => -> (record) { record.data[param_type] }
+ }
+ ).render
+ end
+
+ def results
+ Ci::DailyBuildGroupReportResultsFinder.new(finder_params).execute
+ end
+
+ def finder_params
+ {
+ current_user: current_user,
+ project: project,
+ ref_path: params.require(:ref_path),
+ start_date: start_date,
+ end_date: end_date,
+ limit: MAX_ITEMS
+ }
+ end
+
+ def start_date
+ strong_memoize(:start_date) do
+ start_date = Date.parse(params.require(:start_date))
+
+ # The start_date cannot be older than `end_date - 90 days`
+ [start_date, end_date - REPORT_WINDOW].max
+ end
+ end
+
+ def end_date
+ strong_memoize(:end_date) do
+ Date.parse(params.require(:end_date))
+ end
+ end
+
+ def allowed_param_types
+ Ci::DailyBuildGroupReportResult::PARAM_TYPES
+ end
+
+ def param_type
+ params.require(:param_type)
+ end
+end