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

Commit 55a2757

Browse files
committed
Add a sunburst internal endpoint
1 parent de5e284 commit 55a2757

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

api/internal/coverage/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import services.components as components_service
1010
from api.shared.mixins import RepoPropertyMixin
1111
from api.shared.permissions import RepositoryArtifactPermissions
12-
from api.shared.report.serializers import TreeSerializer
12+
from api.shared.report.serializers import SunburstSerializer, TreeSerializer
1313
from services.path import ReportPaths
1414

1515

@@ -67,3 +67,9 @@ def tree(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Response:
6767
paths = self.get_object()
6868
serializer = TreeSerializer(paths.single_directory(), many=True)
6969
return Response(serializer.data)
70+
71+
@action(detail=False, methods=["get"], url_path="sunburst")
72+
def sunburst(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Response:
73+
paths = self.get_object()
74+
serializer = SunburstSerializer(paths.single_directory(), many=True)
75+
return Response(serializer.data)

api/shared/report/serializers.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TreeSerializer(serializers.Serializer):
1414
partials = serializers.IntegerField()
1515
misses = serializers.IntegerField()
1616

17-
def to_representation(self, instance):
17+
def to_representation(self, instance: Dir) -> dict:
1818
depth = self.context.get("depth", 1)
1919
max_depth = self.context.get("max_depth", math.inf)
2020
res = super().to_representation(instance)
@@ -29,3 +29,25 @@ def to_representation(self, instance):
2929
},
3030
).data
3131
return res
32+
33+
34+
class SunburstSerializer(serializers.Serializer):
35+
name = serializers.CharField()
36+
full_path = serializers.CharField()
37+
value = serializers.FloatField()
38+
39+
def to_representation(self, instance: Dir) -> dict:
40+
depth = self.context.get("depth", 1)
41+
max_depth = self.context.get("max_depth", math.inf)
42+
res = super().to_representation(instance)
43+
if isinstance(instance, Dir):
44+
if depth < max_depth:
45+
res["children"] = SunburstSerializer(
46+
instance.children,
47+
many=True,
48+
context={
49+
"depth": depth + 1,
50+
"max_depth": max_depth,
51+
},
52+
).data
53+
return res

0 commit comments

Comments
 (0)