|
@@ -1,5 +1,3 @@
|
|
|
-from typing import Any
|
|
|
-
|
|
|
from rest_framework.request import Request
|
|
|
from rest_framework.response import Response
|
|
|
|
|
@@ -9,22 +7,37 @@ from sentry.api.base import region_silo_endpoint
|
|
|
from sentry.api.bases.group import GroupEndpoint
|
|
|
from sentry.issues.related import find_related_issues
|
|
|
from sentry.models.group import Group
|
|
|
+from sentry.types.ratelimit import RateLimit, RateLimitCategory
|
|
|
|
|
|
|
|
|
@region_silo_endpoint
|
|
|
class RelatedIssuesEndpoint(GroupEndpoint):
|
|
|
owner = ApiOwner.ISSUES
|
|
|
publish_status = {"GET": ApiPublishStatus.EXPERIMENTAL}
|
|
|
+ enforce_rate_limit = True
|
|
|
+ rate_limits = {
|
|
|
+ "GET": {
|
|
|
+ RateLimitCategory.IP: RateLimit(limit=15, window=5),
|
|
|
+ RateLimitCategory.USER: RateLimit(limit=15, window=5),
|
|
|
+ RateLimitCategory.ORGANIZATION: RateLimit(limit=15, window=1),
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ # We get a Group object since the endpoint is /issues/{issue_id}/related-issues
|
|
|
def get(self, _: Request, group: Group) -> Response:
|
|
|
+ """
|
|
|
+ Retrieve related issues for an Issue
|
|
|
+ ````````````````````````````````````
|
|
|
+ Related issues can be based on the same root cause or trace connected.
|
|
|
+
|
|
|
+ :pparam string group_id: the ID of the issue
|
|
|
+ """
|
|
|
related_issues = find_related_issues(group)
|
|
|
- # Backward compatible for UI
|
|
|
- response: dict[str, Any] = {
|
|
|
- related_set["type"]: [int(g.id) for g in related_set["data"]]
|
|
|
- for related_set in related_issues
|
|
|
- }
|
|
|
- response["data"] = [
|
|
|
- {"type": related_set["type"], "data": [int(g.id) for g in related_set["data"]]}
|
|
|
- for related_set in related_issues
|
|
|
- ]
|
|
|
- return Response(response)
|
|
|
+ return Response(
|
|
|
+ {
|
|
|
+ "data": [
|
|
|
+ {"type": related_set["type"], "data": related_set["data"]}
|
|
|
+ for related_set in related_issues
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ )
|