Skip to content

Commit 0bdecc6

Browse files
committed
🔧 chore: change up slack thread util method
1 parent 44784f7 commit 0bdecc6

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/sentry/integrations/slack/actions/notification.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,27 @@ def _send_notification_action_notification(
394394
open_period_start = open_period_start_for_group(event.group)
395395
new_notification_message_object.open_period_start = open_period_start
396396

397+
thread_ts = None
397398
with MessagingInteractionEvent(
398399
MessagingInteractionType.GET_PARENT_NOTIFICATION, SlackMessagingSpec()
399400
).capture() as lifecycle:
400-
thread_ts = NotificationActionThreadUtils._get_notification_action_thread_ts(
401-
lifecycle=lifecycle,
402-
event=event,
403-
new_notification_message_object=new_notification_message_object,
404-
organization=self.project.organization,
405-
action=action,
406-
open_period_start=open_period_start,
407-
thread_option_default=ISSUE_ALERTS_THREAD_DEFAULT,
401+
parent_notification_message = (
402+
NotificationActionThreadUtils._get_notification_action_for_notification_action(
403+
lifecycle=lifecycle,
404+
action=action,
405+
group=event.group,
406+
organization=self.project.organization,
407+
open_period_start=open_period_start,
408+
thread_option_default=ISSUE_ALERTS_THREAD_DEFAULT,
409+
)
408410
)
409411

412+
if parent_notification_message is not None:
413+
new_notification_message_object.parent_notification_message_id = (
414+
parent_notification_message.id
415+
)
416+
thread_ts = parent_notification_message.message_identifier
417+
410418
self._send_notification(
411419
event=event,
412420
futures=futures,

src/sentry/integrations/slack/utils/threads.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import logging
22
from datetime import datetime
33

4-
from sentry.eventstore.models import GroupEvent
54
from sentry.integrations.repository import get_default_notification_action_repository
65
from sentry.integrations.repository.base import NotificationMessageValidationError
76
from sentry.integrations.repository.notification_action import (
87
NewNotificationActionNotificationMessage,
8+
NotificationActionNotificationMessage,
99
NotificationActionNotificationMessageRepository,
1010
)
1111
from sentry.integrations.utils.metrics import EventLifecycle
12+
from sentry.models.group import Group
1213
from sentry.models.options.organization_option import OrganizationOption
1314
from sentry.models.organization import Organization
1415
from sentry.workflow_engine.models.action import Action
@@ -46,16 +47,15 @@ def _save_notification_action_message(
4647
pass
4748

4849
@classmethod
49-
def _get_notification_action_thread_ts(
50+
def _get_notification_action_for_notification_action(
5051
cls,
5152
organization: Organization,
5253
lifecycle: EventLifecycle,
5354
action: Action,
54-
event: GroupEvent,
55+
group: Group,
5556
open_period_start: datetime | None,
56-
new_notification_message_object: NewNotificationActionNotificationMessage,
5757
thread_option_default: bool,
58-
) -> str | None:
58+
) -> NotificationActionNotificationMessage | None:
5959
"""Find the thread in which to post a notification action notification as a reply.
6060
6161
Return None to post the notification as a top-level message.
@@ -69,23 +69,18 @@ def _get_notification_action_thread_ts(
6969
):
7070
return None
7171

72+
parent_notification_message: NotificationActionNotificationMessage | None = None
7273
try:
7374
action_repository: NotificationActionNotificationMessageRepository = (
7475
get_default_notification_action_repository()
7576
)
7677
parent_notification_message = action_repository.get_parent_notification_message(
7778
action=action,
78-
group=event.group,
79+
group=group,
7980
open_period_start=open_period_start,
8081
)
8182
except Exception as e:
8283
lifecycle.record_halt(e)
8384
return None
8485

85-
if parent_notification_message is None:
86-
return None
87-
88-
new_notification_message_object.parent_notification_message_id = (
89-
parent_notification_message.id
90-
)
91-
return parent_notification_message.message_identifier
86+
return parent_notification_message

0 commit comments

Comments
 (0)