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 'lib/gitlab/ci/reports/coverage_report_generator.rb')
-rw-r--r--lib/gitlab/ci/reports/coverage_report_generator.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/gitlab/ci/reports/coverage_report_generator.rb b/lib/gitlab/ci/reports/coverage_report_generator.rb
new file mode 100644
index 00000000000..fd73ed6fd25
--- /dev/null
+++ b/lib/gitlab/ci/reports/coverage_report_generator.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Reports
+ class CoverageReportGenerator
+ include Gitlab::Utils::StrongMemoize
+
+ def initialize(pipeline)
+ @pipeline = pipeline
+ end
+
+ def report
+ coverage_report = Gitlab::Ci::Reports::CoverageReport.new
+
+ # Return an empty report if the pipeline is a child pipeline.
+ # Since the coverage report is used in a merge request report,
+ # we are only interested in the coverage report from the root pipeline.
+ return coverage_report if @pipeline.child?
+
+ coverage_report.tap do |coverage_report|
+ report_builds.find_each do |build|
+ build.each_report(::Ci::JobArtifact::COVERAGE_REPORT_FILE_TYPES) do |file_type, blob|
+ Gitlab::Ci::Parsers.fabricate!(file_type).parse!(
+ blob,
+ coverage_report,
+ project_path: @pipeline.project.full_path,
+ worktree_paths: @pipeline.all_worktree_paths
+ )
+ end
+ end
+ end
+ end
+
+ private
+
+ def report_builds
+ if child_pipeline_feature_enabled?
+ @pipeline.latest_report_builds_in_self_and_descendants(::Ci::JobArtifact.coverage_reports)
+ else
+ @pipeline.latest_report_builds(::Ci::JobArtifact.coverage_reports)
+ end
+ end
+
+ def child_pipeline_feature_enabled?
+ strong_memoize(:feature_enabled) do
+ Feature.enabled?(:ci_child_pipeline_coverage_reports, @pipeline.project)
+ end
+ end
+ end
+ end
+ end
+end