-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
♻️ ref: refactor notification building utils to prevent circular dependencies #88030
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
from sentry import features | ||
from sentry.eventstore.models import Event, GroupEvent | ||
from sentry.integrations.slack.message_builder.types import LEVEL_TO_COLOR, SLACK_URL_FORMAT | ||
from sentry.integrations.messaging.types import LEVEL_TO_COLOR | ||
from sentry.integrations.types import EXTERNAL_PROVIDERS, ExternalProviders | ||
from sentry.issues.grouptype import GroupCategory | ||
from sentry.models.environment import Environment | ||
|
@@ -173,7 +173,7 @@ def build_attachment_text(group: Group, event: Event | GroupEvent | None = None) | |
|
||
|
||
def build_attachment_replay_link( | ||
group: Group, event: Event | GroupEvent | None = None, url_format: str = SLACK_URL_FORMAT | ||
group: Group, url_format: str, event: Event | GroupEvent | None = None | ||
) -> str | None: | ||
has_replay = features.has("organizations:session-replay", group.organization) | ||
has_slack_links = features.has( | ||
|
@@ -199,8 +199,8 @@ def build_rule_url(rule: Any, group: Group, project: Project) -> str: | |
def build_footer( | ||
group: Group, | ||
project: Project, | ||
url_format: str, | ||
rules: Sequence[Rule] | None = None, | ||
url_format: str = SLACK_URL_FORMAT, | ||
) -> str: | ||
footer = f"{group.qualified_short_id}" | ||
if rules: | ||
|
@@ -210,9 +210,6 @@ def build_footer( | |
text = rules[0].label if rules[0].label else "Test Alert" | ||
footer += f" via {url_format.format(text=text, url=rule_url)}" | ||
|
||
if url_format == SLACK_URL_FORMAT: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slack is clearly doing its own thing, so lets give it its own specific method instead of having this 1 tiny function do all the heavy lifting |
||
footer = url_format.format(text=text, url=rule_url) | ||
|
||
if len(rules) > 1: | ||
footer += f" (+{len(rules) - 1} other)" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Attachment colors used for issues with no actions take. | ||
|
||
LEVEL_TO_COLOR = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is generic, so lets not keep it with Slack |
||
"_actioned_issue": "#EDEEEF", | ||
"_incident_resolved": "#4DC771", | ||
"debug": "#FBE14F", | ||
"error": "#E03E2F", | ||
"fatal": "#FA4747", | ||
"info": "#2788CE", | ||
"warning": "#FFC227", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,6 @@ | |
SlackBlock = dict[str, Any] | ||
SlackBody = Union[SlackAttachment, SlackBlock] | ||
|
||
# Attachment colors used for issues with no actions take. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved outside of slack since its generic |
||
LEVEL_TO_COLOR = { | ||
"_actioned_issue": "#EDEEEF", | ||
"_incident_resolved": "#4DC771", | ||
"debug": "#FBE14F", | ||
"error": "#E03E2F", | ||
"fatal": "#FA4747", | ||
"info": "#2788CE", | ||
"warning": "#FFC227", | ||
} | ||
|
||
INCIDENT_COLOR_MAPPING = { | ||
"Resolved": "_incident_resolved", | ||
"Warning": "warning", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from collections.abc import Sequence | ||
|
||
from sentry.integrations.messaging.message_builder import build_rule_url | ||
from sentry.integrations.slack.message_builder.types import SLACK_URL_FORMAT | ||
from sentry.models.group import Group | ||
from sentry.models.project import Project | ||
from sentry.models.rule import Rule | ||
|
||
|
||
def build_slack_footer( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slack gets its own method thats specific to it since it styles things differently |
||
group: Group, | ||
project: Project, | ||
rules: Sequence[Rule] | None = None, | ||
) -> str: | ||
footer = f"{group.qualified_short_id}" | ||
|
||
if rules: | ||
rule_url = build_rule_url(rules[0], group, project) | ||
# If this notification is triggered via the "Send Test Notification" | ||
# button then the label is not defined, but the url works. | ||
text = rules[0].label if rules[0].label else "Test Alert" | ||
footer = SLACK_URL_FORMAT.format(text=text, url=rule_url) | ||
|
||
if len(rules) > 1: | ||
footer += f" (+{len(rules) - 1} other)" | ||
Comment on lines
+16
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new unit test on this util would be appreciated. |
||
|
||
return footer |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,7 @@ def test_basic(self, mock_record): | |
notification_uuid=notification_uuid, | ||
), | ||
"color": LEVEL_TO_COLOR["error"], | ||
"footer": {"text": build_footer(self.event.group, self.event.project, None, "{text}")}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reorder required because of optional args |
||
"footer": {"text": build_footer(self.event.group, self.event.project, "{text}", None)}, | ||
"fields": [], | ||
"timestamp": self.event.timestamp, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enforcing u pass a url_format