Просмотр исходного кода

feat(slack): Change text in slack threads (#70087)

When creating a slack notification for threads, use `"this issue"`
instead of explicitly adding the issue name
Yash Kamothi 10 месяцев назад
Родитель
Сommit
87c59af93e

+ 1 - 1
src/sentry/integrations/slack/service.py

@@ -8,11 +8,11 @@ from sentry.integrations.repository.issue_alert import (
     IssueAlertNotificationMessageRepository,
 )
 from sentry.integrations.slack import BlockSlackMessageBuilder, SlackClient
+from sentry.integrations.slack.threads.activity_notifications import AssignedActivityNotification
 from sentry.integrations.utils.common import get_active_integration_for_organization
 from sentry.models.activity import Activity
 from sentry.models.rule import Rule
 from sentry.notifications.notifications.activity.archive import ArchiveActivityNotification
-from sentry.notifications.notifications.activity.assigned import AssignedActivityNotification
 from sentry.notifications.notifications.activity.base import ActivityNotification
 from sentry.notifications.notifications.activity.escalating import EscalatingActivityNotification
 from sentry.notifications.notifications.activity.regression import RegressionActivityNotification

+ 0 - 0
src/sentry/integrations/slack/threads/__init__.py


+ 17 - 0
src/sentry/integrations/slack/threads/activity_notifications.py

@@ -0,0 +1,17 @@
+from collections.abc import Mapping
+from typing import Any
+
+from sentry.notifications.notifications.activity.assigned import (
+    AssignedActivityNotification as BaseAssignedActivityNotification,
+)
+
+
+class AssignedActivityNotification(BaseAssignedActivityNotification):
+    """
+    This notification overrides the base AssignedActivityNotification text template to remove the explicit issue name,
+    and instead leverages "this issue" since this notification is already attached to an existing notification where
+    the issue name exists.
+    """
+
+    def get_description(self) -> tuple[str, str | None, Mapping[str, Any]]:
+        return "{author} assigned this issue to {assignee}", None, {"assignee": self.get_assignee()}

+ 0 - 0
tests/sentry/integrations/slack/threads/__init__.py


+ 0 - 0
tests/sentry/integrations/slack/threads/activity_notifications/__init__.py


+ 31 - 0
tests/sentry/integrations/slack/threads/activity_notifications/test_assigned_activity_notification.py

@@ -0,0 +1,31 @@
+from sentry.integrations.slack.threads.activity_notifications import AssignedActivityNotification
+from sentry.models.activity import Activity
+from sentry.testutils.cases import TestCase
+from sentry.types.activity import ActivityType
+
+
+class _BaseTestCase(TestCase):
+    def setUp(self) -> None:
+        self.assigned_activity = Activity.objects.create(
+            group=self.group,
+            project=self.project,
+            type=ActivityType.ASSIGNED.value,
+            user_id=self.user.id,
+            data={
+                "assignee": self.user.id,
+            },
+        )
+        self.obj = AssignedActivityNotification(self.assigned_activity)
+
+
+class TestGetDescription(_BaseTestCase):
+    def test_returns_correct_template(self) -> None:
+        template, _, _ = self.obj.get_description()
+        assert template == "{author} assigned this issue to {assignee}"
+
+
+class TestDescriptionAsTest(_BaseTestCase):
+    def test_returns_correct_text(self) -> None:
+        template, _, params = self.obj.get_description()
+        text = self.obj.description_as_text(template, params)
+        assert text == "admin@localhost assigned this issue to themselves"