debian-mirror-gitlab/app/services/ci/generate_coverage_reports_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
module Ci
# TODO: a couple of points with this approach:
# + reuses existing architecture and reactive caching
# - it's not a report comparison and some comparing features must be turned off.
# see CompareReportsBaseService for more notes.
# issue: https://gitlab.com/gitlab-org/gitlab/issues/34224
class GenerateCoverageReportsService < CompareReportsBaseService
def execute(base_pipeline, head_pipeline)
merge_request = MergeRequest.find_by_id(params[:id])
{
status: :parsed,
key: key(base_pipeline, head_pipeline),
2021-03-11 19:13:27 +05:30
data: head_pipeline.pipeline_artifacts.find_by_file_type(:code_coverage).present.for_files(merge_request.new_paths)
2020-04-08 14:13:33 +05:30
}
2021-06-08 01:23:25 +05:30
rescue StandardError => e
2021-04-29 21:17:54 +05:30
Gitlab::ErrorTracking.track_exception(
e,
project_id: project.id,
base_pipeline_id: base_pipeline&.id,
head_pipeline_id: head_pipeline&.id
)
2020-04-08 14:13:33 +05:30
{
status: :error,
key: key(base_pipeline, head_pipeline),
status_reason: _('An error occurred while fetching coverage reports.')
}
end
def latest?(base_pipeline, head_pipeline, data)
data&.fetch(:key, nil) == key(base_pipeline, head_pipeline)
end
2022-08-13 15:12:31 +05:30
private
def key(base_pipeline, head_pipeline)
[
base_pipeline&.id, last_update_timestamp(base_pipeline),
head_pipeline&.id, last_update_timestamp(head_pipeline)
]
end
def last_update_timestamp(pipeline_hierarchy)
2022-10-11 01:57:18 +05:30
pipeline_hierarchy&.self_and_project_descendants&.maximum(:updated_at)
2022-08-13 15:12:31 +05:30
end
2020-04-08 14:13:33 +05:30
end
end