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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,6 @@ module = [
"sentry.plugins",
"sentry.plugins.base",
"sentry.plugins.base.binding_manager",
"sentry.plugins.base.structs",
"sentry.plugins.interfaces.*",
"sentry.plugins.providers",
"sentry.plugins.providers.base",
Expand Down
17 changes: 8 additions & 9 deletions src/sentry/notifications/notifications/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(
) -> None:
event = notification.event
group = event.group
assert group is not None
project = group.project
super().__init__(project, notification_uuid)
self.group = group
Expand All @@ -100,13 +101,9 @@ def __init__(
self.fallthrough_choice = fallthrough_choice
self.rules = notification.rules

if (
event.group.issue_category in GROUP_CATEGORIES_CUSTOM_EMAIL
or event.group.issue_type.type_id
in (
PerformanceP95EndpointRegressionGroupType.type_id,
ProfileFunctionRegressionType.type_id,
)
if group.issue_category in GROUP_CATEGORIES_CUSTOM_EMAIL or group.issue_type.type_id in (
PerformanceP95EndpointRegressionGroupType.type_id,
ProfileFunctionRegressionType.type_id,
):
# profile issues use the generic template for now
if (
Expand All @@ -115,10 +112,10 @@ def __init__(
and event.occurrence.evidence_data.get("template_name") == "profile"
):
email_template_name = GENERIC_TEMPLATE_NAME
elif event.group.issue_category in PERFORMANCE_ISSUE_CATEGORIES:
elif group.issue_category in PERFORMANCE_ISSUE_CATEGORIES:
email_template_name = "performance"
else:
email_template_name = event.group.issue_category.name.lower()
email_template_name = group.issue_category.name.lower()
else:
email_template_name = GENERIC_TEMPLATE_NAME

Expand Down Expand Up @@ -247,6 +244,7 @@ def get_context(self) -> MutableMapping[str, Any]:
)

if self.group.issue_category in PERFORMANCE_ISSUE_CATEGORIES and template_name != "profile":
assert isinstance(self.event, GroupEvent)
# This can't use data from the occurrence at the moment, so we'll keep fetching the event
# and gathering span evidence.

Expand Down Expand Up @@ -278,6 +276,7 @@ def get_context(self) -> MutableMapping[str, Any]:
context["culprit"] = self.event.occurrence.culprit

if self.group.issue_category not in GROUP_CATEGORIES_CUSTOM_EMAIL:
assert isinstance(self.event, GroupEvent)
generic_issue_data_html = get_generic_data(self.event)
if generic_issue_data_html:
context.update(
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/notifications/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_suspect_commits_by_group_id(
return list(commits.values())


def get_commits(project: Project, event: Event) -> Sequence[Mapping[str, Any]]:
def get_commits(project: Project, event: Event | GroupEvent) -> Sequence[Mapping[str, Any]]:
# let's identify possible suspect commits and owners
commits: MutableMapping[str, Mapping[str, Any]] = {}
try:
Expand Down
25 changes: 16 additions & 9 deletions src/sentry/plugins/base/structs.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
__all__ = ("Annotation", "Notification")
from __future__ import annotations

import warnings
__all__ = ("Notification",)

import warnings
from collections.abc import Sequence
from typing import TYPE_CHECKING

class Annotation:
def __init__(self, label, url=None, description=None):
self.label = label
self.url = url
self.description = description
if TYPE_CHECKING:
from sentry.models.rule import Rule
from sentry.notifications.types import NotificationOrigin
from sentry.services.eventstore.models import Event, GroupEvent


class Notification:
def __init__(self, event, rule=None, rules=None):
def __init__(
self,
event: Event | GroupEvent,
rule: Rule | NotificationOrigin | None = None,
rules: Sequence[Rule | NotificationOrigin] | None = None,
) -> None:
if rule and not rules:
rules = [rule]

self.event = event
self.rules = rules or []

@property
def rule(self):
def rule(self) -> Rule | NotificationOrigin:
warnings.warn(
"Notification.rule is deprecated. Switch to Notification.rules.", DeprecationWarning
)
Expand Down
Loading