This repository was archived by the owner on Jun 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathbundle_analysis.py
More file actions
67 lines (56 loc) · 2.28 KB
/
bundle_analysis.py
File metadata and controls
67 lines (56 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from typing import Union
from shared.api_archive.archive import ArchiveService
from shared.bundle_analysis import (
BundleAnalysisReportLoader,
MissingBaseReportError,
MissingHeadReportError,
)
from shared.storage import get_appropriate_storage_service
from core.models import Commit
from graphql_api.types.comparison.comparison import MissingBaseReport, MissingHeadReport
from reports.models import CommitReport
from services.bundle_analysis import BundleAnalysisComparison, BundleAnalysisReport
def load_bundle_analysis_comparison(
base_commit: Commit, head_commit: Commit
) -> Union[BundleAnalysisComparison, MissingHeadReport, MissingBaseReport]:
head_report = CommitReport.objects.filter(
report_type=CommitReport.ReportType.BUNDLE_ANALYSIS, commit=head_commit
).first()
if head_report is None:
return MissingHeadReport()
base_report = CommitReport.objects.filter(
report_type=CommitReport.ReportType.BUNDLE_ANALYSIS, commit=base_commit
).first()
if base_report is None:
return MissingBaseReport()
loader = BundleAnalysisReportLoader(
storage_service=get_appropriate_storage_service(head_commit.repository.repoid),
repo_key=ArchiveService.get_archive_hash(head_commit.repository),
)
try:
return BundleAnalysisComparison(
loader=loader,
base_report_key=base_report.external_id,
head_report_key=head_report.external_id,
repository=head_commit.repository,
)
except MissingBaseReportError:
return MissingBaseReport()
except MissingHeadReportError:
return MissingHeadReport()
def load_bundle_analysis_report(
commit: Commit,
) -> Union[BundleAnalysisReport, MissingHeadReport, MissingBaseReport]:
report = CommitReport.objects.filter(
report_type=CommitReport.ReportType.BUNDLE_ANALYSIS, commit=commit
).first()
if report is None:
return MissingHeadReport()
loader = BundleAnalysisReportLoader(
storage_service=get_appropriate_storage_service(commit.repository.repoid),
repo_key=ArchiveService.get_archive_hash(commit.repository),
)
report = loader.load(report.external_id)
if report is None:
return MissingHeadReport()
return BundleAnalysisReport(report)