Repository: getsentry/sentry

Issue:
Swap inbox reason for substatus in issue alert emails
The header in this pr https://github.com/getsentry/sentry/pull/48762 is using the inbox reason.

It needs to use the substatus



Discussion:

Resolving patch:
diff --git a/src/sentry/models/groupinbox.py b/src/sentry/models/groupinbox.py
--- a/src/sentry/models/groupinbox.py
+++ b/src/sentry/models/groupinbox.py
@@ -1,6 +1,5 @@
 import logging
 from enum import Enum
-from typing import Optional
 
 import jsonschema
 from django.db import models
@@ -146,14 +145,3 @@ def get_inbox_details(group_list):
     }
 
     return inbox_stats
-
-
-def get_inbox_reason_text(group_inbox: Optional[GroupInbox]):
-    reason = GroupInboxReason(group_inbox.reason) if group_inbox else None
-    if reason == GroupInboxReason.NEW:
-        return "New issue"
-    elif reason == GroupInboxReason.REGRESSION:
-        return "Regressed issue"
-    elif reason == GroupInboxReason.ONGOING:
-        return "Ongoing issue"
-    return "New Alert"
diff --git a/src/sentry/notifications/notifications/rules.py b/src/sentry/notifications/notifications/rules.py
--- a/src/sentry/notifications/notifications/rules.py
+++ b/src/sentry/notifications/notifications/rules.py
@@ -9,8 +9,7 @@
 from sentry import features
 from sentry.db.models import Model
 from sentry.issues.grouptype import GROUP_CATEGORIES_CUSTOM_EMAIL, GroupCategory
-from sentry.models import UserOption
-from sentry.models.groupinbox import GroupInbox, get_inbox_reason_text
+from sentry.models import Group, GroupSubStatus, UserOption
 from sentry.notifications.notifications.base import ProjectNotification
 from sentry.notifications.types import (
     ActionTargetType,
@@ -39,6 +38,16 @@
 logger = logging.getLogger(__name__)
 
 
+def get_group_substatus_text(group: Group) -> str:
+    if group.substatus == GroupSubStatus.NEW:
+        return "New issue"
+    elif group.substatus == GroupSubStatus.REGRESSED:
+        return "Regressed issue"
+    elif group.substatus == GroupSubStatus.ONGOING:
+        return "Ongoing issue"
+    return "New Alert"
+
+
 class AlertRuleNotification(ProjectNotification):
     message_builder = "IssueNotificationMessageBuilder"
     metrics_key = "issue_alert"
@@ -118,10 +127,7 @@ def get_context(self) -> MutableMapping[str, Any]:
             fallthrough_choice=self.fallthrough_choice,
         )
         fallback_params: MutableMapping[str, str] = {}
-        group_inbox_reason = GroupInbox.objects.filter(
-            group=self.group, project=self.project
-        ).first()
-        group_header = get_inbox_reason_text(group_inbox_reason)
+        group_header = get_group_substatus_text(self.group)
 
         context = {
             "project_label": self.project.get_full_name(),
diff --git a/src/sentry/web/frontend/debug/mail.py b/src/sentry/web/frontend/debug/mail.py
--- a/src/sentry/web/frontend/debug/mail.py
+++ b/src/sentry/web/frontend/debug/mail.py
@@ -36,6 +36,7 @@
     Activity,
     Group,
     GroupStatus,
+    GroupSubStatus,
     Organization,
     OrganizationMember,
     Project,
@@ -43,10 +44,10 @@
     Team,
     User,
 )
-from sentry.models.groupinbox import GroupInbox, GroupInboxReason, get_inbox_reason_text
 from sentry.notifications.notifications.activity import EMAIL_CLASSES_BY_TYPE
 from sentry.notifications.notifications.base import BaseNotification
 from sentry.notifications.notifications.digest import DigestNotification
+from sentry.notifications.notifications.rules import get_group_substatus_text
 from sentry.notifications.types import GroupSubscriptionReason
 from sentry.notifications.utils import get_group_settings_link, get_interface_list, get_rules
 from sentry.testutils.helpers.datetime import before_now
@@ -231,7 +232,7 @@ def make_generic_event(project):
     return generic_group.get_latest_event()
 
 
-def get_shared_context(rule, org, project, group, event, group_inbox: GroupInbox | None = None):
+def get_shared_context(rule, org, project, group, event):
     rules = get_rules([rule], org, project)
     snooze_alert = len(rules) > 0
     snooze_alert_url = rules[0].status_url + urlencode({"mute": "1"}) if snooze_alert else ""
@@ -239,7 +240,7 @@ def get_shared_context(rule, org, project, group, event, group_inbox: GroupInbox
         "rule": rule,
         "rules": rules,
         "group": group,
-        "group_header": get_inbox_reason_text(group_inbox),
+        "group_header": get_group_substatus_text(group),
         "event": event,
         "timezone": pytz.timezone("Europe/Vienna"),
         # http://testserver/organizations/example/issues/<issue-id>/?referrer=alert_email
@@ -417,22 +418,22 @@ def alert(request):
     event = make_error_event(request, project, platform)
     group = event.group
 
+    group.substatus = random.choice(
+        [GroupSubStatus.ESCALATING, GroupSubStatus.NEW, GroupSubStatus.REGRESSED]
+    )
+
     rule = Rule(id=1, label="An example rule")
     notification_reason = (
         random.randint(0, 1) > 0
         and f"We notified all members in the {project.get_full_name()} project of this issue"
         or None
     )
-    inbox_reason = random.choice(
-        [GroupInboxReason.NEW, GroupInboxReason.REGRESSION, GroupInboxReason.ONGOING]
-    )
-    group_inbox = GroupInbox(reason=inbox_reason.value, group=group, project=project)
 
     return MailPreview(
         html_template="sentry/emails/error.html",
         text_template="sentry/emails/error.txt",
         context={
-            **get_shared_context(rule, org, project, group, event, group_inbox),
+            **get_shared_context(rule, org, project, group, event),
             "interfaces": get_interface_list(event),
             "project_label": project.slug,
             "commits": json.loads(COMMIT_EXAMPLE),


Test patch:
diff --git a/tests/sentry/mail/test_adapter.py b/tests/sentry/mail/test_adapter.py
--- a/tests/sentry/mail/test_adapter.py
+++ b/tests/sentry/mail/test_adapter.py
@@ -21,6 +21,7 @@
 from sentry.models import (
     Activity,
     GroupRelease,
+    GroupSubStatus,
     Integration,
     NotificationSetting,
     Organization,
@@ -37,7 +38,6 @@
     UserOption,
     UserReport,
 )
-from sentry.models.groupinbox import GroupInboxReason, add_group_to_inbox
 from sentry.notifications.notifications.rules import AlertRuleNotification
 from sentry.notifications.types import (
     ActionTargetType,
@@ -1104,11 +1104,13 @@ def test_notify_with_user_tag_edge_cases(self):
             )
 
     @with_feature("organizations:issue-states")
-    def test_has_inbox_reason(self):
+    def test_group_substatus_header(self):
         event = self.store_event(
             data={"message": "Hello world", "level": "error"}, project_id=self.project.id
         )
-        add_group_to_inbox(event.group, GroupInboxReason.REGRESSION)
+        # Header is based on the group substatus
+        event.group.substatus = GroupSubStatus.REGRESSED
+        event.group.save()
 
         rule = Rule.objects.create(project=self.project, label="my rule")
         ProjectOwnership.objects.create(project_id=self.project.id, fallthrough=True)