From 9f46488805e86b1bc341ea1620b866016c2ce5ed Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 May 2020 14:34:42 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-0-stable-ee --- .../daily_build_group_report_results_controller.rb | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 app/controllers/projects/ci/daily_build_group_report_results_controller.rb (limited to 'app/controllers/projects/ci') 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 -- cgit v1.2.1