Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 81f1a25

Browse files
authored
Bundle Analysis: expose bundle report info to GQL (#1004)
1 parent 160f0bd commit 81f1a25

File tree

6 files changed

+178
-0
lines changed

6 files changed

+178
-0
lines changed

graphql_api/tests/test_commit.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,3 +3323,70 @@ def test_bundle_analysis_asset_routes(self, get_storage_service):
33233323
"/login",
33243324
"/super/long/url/path",
33253325
]
3326+
3327+
@patch("graphql_api.dataloader.bundle_analysis.get_appropriate_storage_service")
3328+
def test_bundle_analysis_report_info(self, get_storage_service):
3329+
storage = MemoryStorageService({})
3330+
get_storage_service.return_value = storage
3331+
3332+
head_commit_report = CommitReportFactory(
3333+
commit=self.commit, report_type=CommitReport.ReportType.BUNDLE_ANALYSIS
3334+
)
3335+
3336+
with open(
3337+
"./services/tests/samples/bundle_with_assets_and_modules.sqlite", "rb"
3338+
) as f:
3339+
storage_path = StoragePaths.bundle_report.path(
3340+
repo_key=ArchiveService.get_archive_hash(self.repo),
3341+
report_key=head_commit_report.external_id,
3342+
)
3343+
storage.write_file(get_bucket_name(), storage_path, f)
3344+
3345+
query = """
3346+
query FetchCommit($org: String!, $repo: String!, $commit: String!) {
3347+
owner(username: $org) {
3348+
repository(name: $repo) {
3349+
... on Repository {
3350+
commit(id: $commit) {
3351+
bundleAnalysis {
3352+
bundleAnalysisReport {
3353+
__typename
3354+
... on BundleAnalysisReport {
3355+
bundle(name: "b5") {
3356+
info {
3357+
version
3358+
plugin_name
3359+
plugin_version
3360+
built_at
3361+
duration
3362+
bundler_name
3363+
bundler_version
3364+
}
3365+
}
3366+
}
3367+
}
3368+
}
3369+
}
3370+
}
3371+
}
3372+
}
3373+
}
3374+
"""
3375+
3376+
variables = {
3377+
"org": self.org.username,
3378+
"repo": self.repo.name,
3379+
"commit": self.commit.commitid,
3380+
}
3381+
data = self.gql_request(query, variables=variables)
3382+
commit = data["owner"]["repository"]["commit"]
3383+
3384+
bundle_info = commit["bundleAnalysis"]["bundleAnalysisReport"]["bundle"]["info"]
3385+
3386+
assert bundle_info["version"] == "1"
3387+
assert bundle_info["plugin_name"] == "codecov-vite-bundle-analysis-plugin"
3388+
assert bundle_info["plugin_version"] == "1.0.0"
3389+
assert bundle_info["built_at"] == "2023-12-01 17:17:28.604000"
3390+
assert bundle_info["duration"] == 331
3391+
assert bundle_info["bundler_name"] == "rollup"
3392+
assert bundle_info["bundler_version"] == "3.29.4"

graphql_api/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
bundle_data_bindable,
1818
bundle_module_bindable,
1919
bundle_report_bindable,
20+
bundle_report_info_bindable,
2021
)
2122
from .commit import (
2223
commit,
@@ -148,6 +149,7 @@
148149
bundle_data_bindable,
149150
bundle_module_bindable,
150151
bundle_report_bindable,
152+
bundle_report_info_bindable,
151153
commit_bindable,
152154
commit_bundle_analysis_bindable,
153155
commit_coverage_analytics_bindable,

graphql_api/types/bundle_analysis/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
bundle_data_bindable,
66
bundle_module_bindable,
77
bundle_report_bindable,
8+
bundle_report_info_bindable,
89
)
910
from .comparison import (
1011
bundle_analysis_comparison_bindable,
@@ -26,6 +27,7 @@
2627
"bundle_data_bindable",
2728
"bundle_module_bindable",
2829
"bundle_report_bindable",
30+
"bundle_report_info_bindable",
2931
"bundle_analysis_comparison_bindable",
3032
"bundle_analysis_comparison_result_bindable",
3133
"bundle_comparison_bindable",

graphql_api/types/bundle_analysis/base.graphql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ type BundleAsset {
5858
routes: [String!]
5959
}
6060

61+
type BundleReportInfo {
62+
version: String!
63+
plugin_name: String!
64+
plugin_version: String!
65+
built_at: String!
66+
duration: Int!
67+
bundler_name: String!
68+
bundler_version: String!
69+
}
70+
6171
type BundleReport {
6272
name: String!
6373
moduleCount: Int!
@@ -82,6 +92,7 @@ type BundleReport {
8292
last: Int
8393
before: String
8494
): AssetConnection
95+
info: BundleReportInfo!
8596
}
8697

8798
type BundleAnalysisMeasurements{

graphql_api/types/bundle_analysis/base.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
BundleData,
1818
BundleLoadTime,
1919
BundleReport,
20+
BundleReportInfo,
2021
BundleSize,
2122
ModuleReport,
2223
)
@@ -28,6 +29,7 @@
2829
bundle_module_bindable = ObjectType("BundleModule")
2930
bundle_asset_bindable = ObjectType("BundleAsset")
3031
bundle_report_bindable = ObjectType("BundleReport")
32+
bundle_report_info_bindable = ObjectType("BundleReportInfo")
3133

3234

3335
def _find_index_by_cursor(assets: List, cursor: str) -> int:
@@ -372,3 +374,59 @@ def resolve_bundle_report_is_cached(
372374
bundle_report: BundleReport, info: GraphQLResolveInfo
373375
) -> bool:
374376
return bundle_report.is_cached
377+
378+
379+
@bundle_report_bindable.field("info")
380+
def resolve_bundle_report_info(
381+
bundle_report: BundleReport, info: GraphQLResolveInfo
382+
) -> BundleReportInfo:
383+
return BundleReportInfo(bundle_report.info)
384+
385+
386+
@bundle_report_info_bindable.field("version")
387+
def resolve_bundle_report_info_version(
388+
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
389+
) -> str:
390+
return bundle_report_info.version
391+
392+
393+
@bundle_report_info_bindable.field("plugin_name")
394+
def resolve_bundle_report_info_plugin_name(
395+
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
396+
) -> str:
397+
return bundle_report_info.plugin_name
398+
399+
400+
@bundle_report_info_bindable.field("plugin_version")
401+
def resolve_bundle_report_info_plugin_version(
402+
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
403+
) -> str:
404+
return bundle_report_info.plugin_version
405+
406+
407+
@bundle_report_info_bindable.field("built_at")
408+
def resolve_bundle_report_info_built_at(
409+
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
410+
) -> str:
411+
return bundle_report_info.built_at
412+
413+
414+
@bundle_report_info_bindable.field("duration")
415+
def resolve_bundle_report_info_duration(
416+
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
417+
) -> int:
418+
return bundle_report_info.duration
419+
420+
421+
@bundle_report_info_bindable.field("bundler_name")
422+
def resolve_bundle_report_info_bundler_name(
423+
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
424+
) -> str:
425+
return bundle_report_info.bundler_name
426+
427+
428+
@bundle_report_info_bindable.field("bundler_version")
429+
def resolve_bundle_report_info_bundler_version(
430+
bundle_report_info: BundleReportInfo, info: GraphQLResolveInfo
431+
) -> str:
432+
return bundle_report_info.bundler_version

services/bundle_analysis.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,44 @@ def module_count(self) -> int:
298298
def is_cached(self) -> bool:
299299
return self.report.is_cached()
300300

301+
@cached_property
302+
def info(self) -> dict:
303+
return self.report.info()
304+
305+
306+
@dataclass
307+
class BundleReportInfo(object):
308+
def __init__(self, info: dict) -> None:
309+
self.info = info
310+
311+
@cached_property
312+
def version(self) -> str:
313+
return self.info.get("version", "unknown")
314+
315+
@cached_property
316+
def plugin_name(self) -> str:
317+
return self.info.get("plugin_name", "unknown")
318+
319+
@cached_property
320+
def plugin_version(self) -> str:
321+
return self.info.get("plugin_version", "unknown")
322+
323+
@cached_property
324+
def built_at(self) -> str:
325+
return str(datetime.fromtimestamp(self.info.get("built_at", 0) / 1000))
326+
327+
@cached_property
328+
def duration(self) -> int:
329+
return self.info.get("duration", -1)
330+
331+
@cached_property
332+
def bundler_name(self) -> str:
333+
return self.info.get("bundler_name", "unknown")
334+
335+
@cached_property
336+
def bundler_version(self) -> str:
337+
return self.info.get("bundler_version", "unknown")
338+
301339

302340
@dataclass
303341
class BundleAnalysisReport(object):

0 commit comments

Comments
 (0)