diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-13 18:09:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-13 18:09:34 +0300 |
commit | c4eeda2d3d048e84b331f416472e99ed0e116904 (patch) | |
tree | d2ac30119226e46f54f41961e3eed2cd5b5bdb5b /lib/gitlab/ci/reports | |
parent | cdd5eba514e79c7801ff2eeb76e915e3f31ca5d7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/ci/reports')
-rw-r--r-- | lib/gitlab/ci/reports/coverage_report.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/reports/coverage_report_generator.rb | 53 |
2 files changed, 57 insertions, 0 deletions
diff --git a/lib/gitlab/ci/reports/coverage_report.rb b/lib/gitlab/ci/reports/coverage_report.rb index 201863fd311..cebbb9ae842 100644 --- a/lib/gitlab/ci/reports/coverage_report.rb +++ b/lib/gitlab/ci/reports/coverage_report.rb @@ -10,6 +10,10 @@ module Gitlab @files = {} end + def empty? + @files.empty? + end + def pick(keys) coverage_files = files.select do |key| keys.include?(key) 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 |