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

Commit 6f4df0b

Browse files
committed
Require bundle name in badge url
1 parent 1692987 commit 6f4df0b

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

graphs/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
name="default-badge",
1515
),
1616
re_path(
17-
"branch/(?P<branch>.+)/(graph|graphs)/bundle/badge.(?P<ext>[^/]+)",
17+
"branch/(?P<branch>.+)/(graph|graphs)/bundle/(?P<bundle>.+)/badge.(?P<ext>[^/]+)",
1818
BundleBadgeHandler.as_view(),
1919
name="branch-bundle-badge",
2020
),
2121
re_path(
22-
"(graph|graphs)/bundle/badge.(?P<ext>[^/]+)",
22+
"(graph|graphs)/bundle/(?P<bundle>.+)/badge.(?P<ext>[^/]+)",
2323
BundleBadgeHandler.as_view(),
2424
name="default-bundle-badge",
2525
),

graphs/views.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from api.shared.mixins import RepoPropertyMixin
1515
from core.models import Branch, Pull
1616
from graphs.settings import settings
17-
from services.bundle_analysis import BundleAnalysisReport, load_report
17+
from services.bundle_analysis import load_report
1818
from services.components import commit_components
1919

2020
from .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

270282
class GraphHandler(APIView, RepoPropertyMixin, GraphBadgeAPIMixin):

0 commit comments

Comments
 (0)