Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sentry/integrations/opsgenie/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sentry.integrations.services.integration.model import RpcIntegration
from sentry.integrations.types import IntegrationProviderSlug
from sentry.models.group import Group
from sentry.notifications.types import TEST_NOTIFICATION_ID, NotificationOrigin
from sentry.notifications.types import NotificationOrigin
from sentry.notifications.utils.links import create_link_to_workflow
from sentry.services.eventstore.models import Event, GroupEvent
from sentry.shared_integrations.exceptions import ApiError
Expand Down Expand Up @@ -57,7 +57,7 @@ def _get_workflow_links(
workflow_id = rule.workflow_id
if workflow_id is None:
# Test notifications have no backing workflow, so nothing to link to.
if rule.legacy_rule_id != TEST_NOTIFICATION_ID:
if not rule.is_test_notification():
logger.warning(
"opsgenie.issue_alert.missing_workflow_id",
extra={
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/integrations/slack/actions/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from sentry.notifications.additional_attachment_manager import get_additional_attachment
from sentry.notifications.platform.shadow.capture import record_legacy_render
from sentry.notifications.platform.types import NotificationProviderKey
from sentry.notifications.types import TEST_NOTIFICATION_ID, NotificationOrigin, RuleFuture
from sentry.notifications.types import NotificationOrigin, RuleFuture
from sentry.notifications.utils.open_period import open_period_start_for_group
from sentry.rules.actions import IntegrationEventAction
from sentry.rules.base import CallbackFuture
Expand Down Expand Up @@ -243,7 +243,7 @@ def _send_notification_action_notification(
)
return

if context and context.origin.legacy_rule_id == TEST_NOTIFICATION_ID:
if context and context.origin.is_test_notification():
self._send_notification(
event=event,
futures=futures,
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/notifications/notification_action/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ def build_rule_data_from_action(
) -> RuleData:
action_blob = cls.build_rule_action_blob(action, detector.linked_project.organization.id)

if origin.legacy_rule_id == TEST_NOTIFICATION_ID:
if origin.is_test_notification():
action_blob["legacy_rule_id"] = TEST_NOTIFICATION_ID
else:
assert origin.workflow_id is not None
action_blob["workflow_id"] = origin.workflow_id
if origin.legacy_rule_id is not None:
action_blob["legacy_rule_id"] = origin.legacy_rule_id

if origin.legacy_rule_id == TEST_NOTIFICATION_ID and action.type == Action.Type.EMAIL:
if origin.is_test_notification() and action.type == Action.Type.EMAIL:
action_blob["skipDigests"] = True

return {"actions": [action_blob]}
Expand Down Expand Up @@ -393,7 +393,7 @@ def invoke_legacy_registry(cls, invocation: ActionInvocation) -> None:
)

# Execute the futures
if context.origin.legacy_rule_id == TEST_NOTIFICATION_ID:
if context.origin.is_test_notification():
cls.send_test_notification(invocation.event_data, futures)
else:
cls.execute_futures(invocation.event_data, futures)
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/notifications/platform/slack/renderers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
NotificationRenderedTemplate,
NotificationSource,
)
from sentry.notifications.types import TEST_NOTIFICATION_ID
from sentry.workflow_engine.tasks.utils import fetch_event


Expand Down Expand Up @@ -44,15 +43,16 @@ def render[DataT: NotificationData](
else None
)
scopes = set(integration.metadata.get("scopes") or []) if integration else set()
send_nudge = data.rule.id != TEST_NOTIFICATION_ID and should_send_nudge_block(
origin = data.rule.to_notification_origin()
send_nudge = not origin.is_test_notification() and should_send_nudge_block(
organization=group.organization, notification_uuid=data.notification_uuid
)

blocks_dict = SlackIssuesMessageBuilder(
group=group,
event=event,
tags=set(data.tags) if data.tags else None,
rules=[data.rule.to_notification_origin()],
rules=[origin],
notes=data.notes,
send_nudge=send_nudge,
has_mentions_read_scope=SlackScope.APP_MENTIONS_READ in scopes,
Expand Down
5 changes: 5 additions & 0 deletions src/sentry/notifications/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class NotificationOrigin:
workflow_id: int | None
legacy_rule_id: int | None

def is_test_notification(self) -> bool:
return (
self.workflow_id == TEST_NOTIFICATION_ID or self.legacy_rule_id == TEST_NOTIFICATION_ID
)

@classmethod
def from_legacy_rule(cls, rule: Rule) -> NotificationOrigin:
return cls.from_legacy_data(
Expand Down
12 changes: 12 additions & 0 deletions tests/sentry/notifications/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
from sentry.notifications.models.notificationsettingoption import NotificationSettingOption
from sentry.notifications.types import (
TEST_NOTIFICATION_ID,
NotificationOrigin,
NotificationSettingEnum,
NotificationSettingsOptionEnum,
Expand Down Expand Up @@ -148,6 +149,17 @@ def test_notification_origin_normalizes_legacy_identity(self) -> None:
assert origin.label == rule.label
assert origin.legacy_rule_id == rule.id
assert origin.workflow_id == workflow_id
assert not origin.is_test_notification()

def test_notification_origin_identifies_test_notification(self) -> None:
origin = NotificationOrigin.from_legacy_data(
label="Test notification",
environment_id=None,
data={},
fallback_legacy_rule_id=TEST_NOTIFICATION_ID,
)

assert origin.is_test_notification()

def test_get_email_link_extra_params(self) -> None:
rule: Rule = self.create_project_rule(self.project)
Expand Down
Loading