1414from api .shared .mixins import RepoPropertyMixin
1515from core .models import Branch , Pull
1616from graphs .settings import settings
17- from services .bundle_analysis import BundleAnalysisReport , load_report
17+ from services .bundle_analysis import load_report
1818from services .components import commit_components
1919
2020from .helpers .badge import (
@@ -209,7 +209,7 @@ class BundleBadgeHandler(APIView, RepoPropertyMixin, GraphBadgeAPIMixin):
209209 filename = "bundle-badge"
210210
211211 def get_object (self , request , * args , ** kwargs ):
212- # Validate coverage precision
212+ # Validate precision query param
213213 precision = self .request .query_params .get ("precision" , "2" )
214214 if precision not in self .precisions :
215215 raise NotFound ("Bundle size precision should be one of [ 0 || 1 || 2 ]" )
@@ -218,7 +218,11 @@ def get_object(self, request, *args, **kwargs):
218218 bundle_size_bytes = self .get_bundle_size ()
219219
220220 if self .kwargs .get ("ext" ) == "txt" :
221- return format_bundle_bytes (bundle_size_bytes , precision )
221+ return (
222+ "unknown"
223+ if bundle_size_bytes is None
224+ else format_bundle_bytes (bundle_size_bytes , precision )
225+ )
222226
223227 return get_bundle_badge (bundle_size_bytes , precision )
224228
@@ -253,18 +257,26 @@ def get_bundle_size(self) -> int | None:
253257 log .warning ("Commit not found" , extra = dict (commit = branch .head ))
254258 return None
255259
256- shared_bundle_report = load_report (commit )
260+ commit_bundles = load_report (commit )
257261
258- if shared_bundle_report is None :
262+ if commit_bundles is None :
259263 log .warning (
260264 "Bundle analysis report not found for commit" ,
261265 extra = dict (commit = branch .head ),
262266 )
263267 return None
264268
265- bundle_report = BundleAnalysisReport (shared_bundle_report )
269+ bundle_name = str (self .kwargs .get ("bundle" ))
270+ bundle = commit_bundles .bundle_report (bundle_name )
271+
272+ if bundle is None :
273+ log .warning (
274+ "Bundle with provided name not found for commit" ,
275+ extra = dict (commit = branch .head ),
276+ )
277+ return None
266278
267- return bundle_report . size_total
279+ return bundle . total_size ()
268280
269281
270282class GraphHandler (APIView , RepoPropertyMixin , GraphBadgeAPIMixin ):
0 commit comments