Skip to content

Add a sunburst internal endpoint #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/internal/coverage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import services.components as components_service
from api.shared.mixins import RepoPropertyMixin
from api.shared.permissions import RepositoryArtifactPermissions
from api.shared.report.serializers import TreeSerializer
from api.shared.report.serializers import SunburstSerializer, TreeSerializer
from services.path import ReportPaths


Expand Down Expand Up @@ -67,3 +67,9 @@
paths = self.get_object()
serializer = TreeSerializer(paths.single_directory(), many=True)
return Response(serializer.data)

@action(detail=False, methods=["get"], url_path="sunburst")
def sunburst(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Response:
paths = self.get_object()
serializer = SunburstSerializer(paths.single_directory(), many=True)
return Response(serializer.data)

Check warning on line 75 in api/internal/coverage/views.py

View check run for this annotation

Codecov Notifications / codecov/patch

api/internal/coverage/views.py#L73-L75

Added lines #L73 - L75 were not covered by tests
Comment on lines +70 to +75
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve readability and maintainability, consider refactoring the sunburst method to avoid code duplication with the tree method. You can create a helper method to handle the common logic.

Suggested change
@action(detail=False, methods=["get"], url_path="sunburst")
def sunburst(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Response:
paths = self.get_object()
serializer = SunburstSerializer(paths.single_directory(), many=True)
return Response(serializer.data)
def serialize_paths(self, serializer_class):
paths = self.get_object()
serializer = serializer_class(paths.single_directory(), many=True)
return Response(serializer.data)
@action(detail=False, methods=["get"], url_path="sunburst")
def sunburst(self, request: HttpRequest, *args: Any, **kwargs: Any) -> Response:
return self.serialize_paths(SunburstSerializer)

24 changes: 23 additions & 1 deletion api/shared/report/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
partials = serializers.IntegerField()
misses = serializers.IntegerField()

def to_representation(self, instance):
def to_representation(self, instance: Dir) -> dict:
depth = self.context.get("depth", 1)
max_depth = self.context.get("max_depth", math.inf)
res = super().to_representation(instance)
Expand All @@ -29,3 +29,25 @@
},
).data
return res


class SunburstSerializer(serializers.Serializer):
name = serializers.CharField()
full_path = serializers.CharField()
value = serializers.FloatField()

def to_representation(self, instance: Dir) -> dict:
depth = self.context.get("depth", 1)
max_depth = self.context.get("max_depth", math.inf)
res = super().to_representation(instance)
if isinstance(instance, Dir):
if depth < max_depth:
res["children"] = SunburstSerializer(

Check warning on line 45 in api/shared/report/serializers.py

View check run for this annotation

Codecov Notifications / codecov/patch

api/shared/report/serializers.py#L40-L45

Added lines #L40 - L45 were not covered by tests
instance.children,
many=True,
context={
"depth": depth + 1,
"max_depth": max_depth,
},
).data
return res

Check warning on line 53 in api/shared/report/serializers.py

View check run for this annotation

Codecov Notifications / codecov/patch

api/shared/report/serializers.py#L53

Added line #L53 was not covered by tests
Loading