Skip to content

Commit

Permalink
🐛 fix: fix uptime issue threads
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrajjoshi committed Jan 21, 2025
1 parent de51389 commit 5cc8447
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sentry/integrations/slack/actions/notification.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations

from collections.abc import Generator, Sequence
from datetime import datetime
from logging import Logger, getLogger
from typing import Any

import orjson
from slack_sdk.errors import SlackApiError

from sentry import features
from sentry.api.serializers.rest_framework.rule import ACTION_UUID_KEY
from sentry.constants import ISSUE_ALERTS_THREAD_DEFAULT
from sentry.eventstore.models import GroupEvent
Expand Down Expand Up @@ -39,9 +41,11 @@
unpack_slack_api_error,
)
from sentry.integrations.utils.metrics import EventLifecycle
from sentry.issues.grouptype import GroupCategory
from sentry.models.options.organization_option import OrganizationOption
from sentry.models.rule import Rule
from sentry.notifications.additional_attachment_manager import get_additional_attachment
from sentry.notifications.utils.open_period import open_period_start_for_group
from sentry.rules.actions import IntegrationEventAction
from sentry.rules.base import CallbackFuture
from sentry.types.rules import RuleFuture
Expand Down Expand Up @@ -129,6 +133,17 @@ def send_notification(event: GroupEvent, futures: Sequence[RuleFuture]) -> None:
rule_action_uuid=rule_action_uuid,
)

open_period_start: datetime | None = None
if (
features.has(
"organizations:slack-threads-refactor-uptime", self.project.organization
)
and event.group.issue_category == GroupCategory.UPTIME
):
open_period_start = open_period_start_for_group(event.group)
# Save in the notification message object so it can be used in the repository
new_notification_message_object.open_period_start = open_period_start

def get_thread_ts(lifecycle: EventLifecycle) -> str | None:
"""Find the thread in which to post this notification as a reply.
Expand All @@ -152,6 +167,7 @@ def get_thread_ts(lifecycle: EventLifecycle) -> str | None:
rule_id=rule_id,
group_id=event.group.id,
rule_action_uuid=rule_action_uuid,
open_period_start=open_period_start,
)
except Exception as e:
lifecycle.record_halt(e)
Expand Down

0 comments on commit 5cc8447

Please sign in to comment.