Skip to content

Commit 10f9c3f

Browse files
authored
chore(slack): remove more non-block kit (#68997)
1 parent f186916 commit 10f9c3f

File tree

16 files changed

+13
-137
lines changed

16 files changed

+13
-137
lines changed
Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from __future__ import annotations
22

33
from abc import ABC
4-
from collections.abc import Mapping, MutableMapping, Sequence
4+
from collections.abc import Mapping, MutableMapping
55
from typing import Any
66

77
from sentry.eventstore.models import Event, GroupEvent
8-
from sentry.integrations.slack.message_builder import LEVEL_TO_COLOR, SlackAttachment, SlackBody
8+
from sentry.integrations.slack.message_builder import SlackBody
99
from sentry.models.group import Group
1010
from sentry.notifications.utils.actions import MessageAction
11-
from sentry.utils.assets import get_asset_url
12-
from sentry.utils.http import absolute_uri
1311

1412

1513
def get_slack_button(action: MessageAction) -> Mapping[str, Any]:
@@ -49,46 +47,3 @@ def escape_text(self) -> bool:
4947
Returns True if we need to escape the text in the message.
5048
"""
5149
return False
52-
53-
def _build(
54-
self,
55-
text: str,
56-
title: str | None = None,
57-
title_link: str | None = None,
58-
footer: str | None = None,
59-
color: str | None = None,
60-
actions: Sequence[MessageAction] | None = None,
61-
**kwargs: Any,
62-
) -> SlackAttachment:
63-
"""
64-
Helper to DRY up Slack specific fields.
65-
66-
:param string text: Body text.
67-
:param [string] title: Title text.
68-
:param [string] title_link: Optional URL attached to the title.
69-
:param [string] footer: Footer text.
70-
:param [string] color: The key in the Slack palate table, NOT hex. Default: "info".
71-
:param [list[MessageAction]] actions: List of actions displayed alongside the message.
72-
:param kwargs: Everything else.
73-
"""
74-
# If `footer` string is passed, automatically attach a `footer_icon`.
75-
if footer:
76-
kwargs["footer"] = footer
77-
kwargs["footer_icon"] = str(
78-
absolute_uri(get_asset_url("sentry", "images/sentry-email-avatar.png"))
79-
)
80-
81-
if title:
82-
kwargs["title"] = title
83-
if title_link:
84-
kwargs["title_link"] = title_link
85-
86-
if actions is not None:
87-
kwargs["actions"] = [get_slack_button(action) for action in actions]
88-
89-
return {
90-
"text": text,
91-
"mrkdwn_in": ["text"],
92-
"color": LEVEL_TO_COLOR[color or "info"],
93-
**kwargs,
94-
}

src/sentry/integrations/slack/message_builder/issues.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
CATEGORY_TO_EMOJI,
2929
LEVEL_TO_EMOJI,
3030
SLACK_URL_FORMAT,
31-
SlackAttachment,
3231
SlackBlock,
3332
)
3433
from sentry.integrations.slack.message_builder.base.block import BlockSlackMessageBuilder
@@ -506,7 +505,7 @@ def escape_text(self) -> bool:
506505
"""
507506
return True
508507

509-
def build(self, notification_uuid: str | None = None) -> SlackBlock | SlackAttachment:
508+
def build(self, notification_uuid: str | None = None) -> SlackBlock:
510509
# XXX(dcramer): options are limited to 100 choices, even when nested
511510
text = build_attachment_text(self.group, self.event) or ""
512511
text = text.strip(" \n")

src/sentry/integrations/slack/message_builder/notifications/base.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from collections.abc import Mapping
44
from typing import Any
55

6-
from sentry import features
7-
from sentry.integrations.slack.message_builder import SlackAttachment, SlackBlock
6+
from sentry.integrations.slack.message_builder import SlackBlock
87
from sentry.integrations.slack.message_builder.base.block import BlockSlackMessageBuilder
98
from sentry.integrations.slack.utils.escape import escape_slack_text
109
from sentry.notifications.notifications.base import BaseNotification
@@ -25,7 +24,7 @@ def __init__(
2524
self.context = context
2625
self.recipient = recipient
2726

28-
def build(self) -> SlackAttachment | SlackBlock:
27+
def build(self) -> SlackBlock:
2928
callback_id_raw = self.notification.get_callback_data()
3029
title = self.notification.build_attachment_title(self.recipient)
3130
title_link = self.notification.get_title_link(self.recipient, ExternalProviders.SLACK)
@@ -35,15 +34,6 @@ def build(self) -> SlackAttachment | SlackBlock:
3534
)
3635
actions = self.notification.get_message_actions(self.recipient, ExternalProviders.SLACK)
3736
callback_id = json.dumps(callback_id_raw) if callback_id_raw else None
38-
if not features.has("organizations:slack-block-kit", self.notification.organization):
39-
return self._build(
40-
title=title,
41-
title_link=title_link,
42-
text=text,
43-
footer=footer,
44-
actions=actions,
45-
callback_id=callback_id,
46-
)
4737

4838
first_block_text = ""
4939
if title_link:

src/sentry/integrations/slack/message_builder/notifications/digest.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
from collections.abc import Mapping
44
from typing import Any
55

6-
from sentry import features
76
from sentry.digests import Digest
87
from sentry.digests.utils import get_groups
9-
from sentry.integrations.slack.message_builder import SlackAttachment, SlackBlock
8+
from sentry.integrations.slack.message_builder import SlackBlock
109
from sentry.integrations.slack.message_builder.issues import SlackIssuesMessageBuilder
1110
from sentry.notifications.notifications.digest import DigestNotification
1211
from sentry.services.hybrid_cloud.actor import RpcActor
@@ -24,25 +23,13 @@ def __init__(
2423
super().__init__(notification, context, recipient)
2524
self.notification: DigestNotification = notification
2625

27-
def build(self) -> SlackAttachment | SlackBlock:
26+
def build(self) -> SlackBlock:
2827
"""
2928
It's currently impossible in mypy to have recursive types so we need a
3029
hack to get this to return a SlackBody.
3130
"""
3231
digest: Digest = self.context.get("digest", {})
3332
digest_groups = get_groups(digest)
34-
if not features.has("organizations:slack-block-kit", self.notification.organization):
35-
return [
36-
SlackIssuesMessageBuilder(
37-
group=group,
38-
event=event,
39-
rules=[rule],
40-
issue_details=True,
41-
notification=self.notification,
42-
recipient=self.recipient,
43-
).build()
44-
for rule, group, event in digest_groups
45-
]
4633
blocks = []
4734
for rule, group, event in digest_groups:
4835
alert_as_blocks = SlackIssuesMessageBuilder(

src/sentry/integrations/slack/message_builder/notifications/issues.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections.abc import Mapping
44
from typing import Any
55

6-
from sentry.integrations.slack.message_builder import SlackAttachment, SlackBlock
6+
from sentry.integrations.slack.message_builder import SlackBlock
77
from sentry.integrations.slack.message_builder.issues import SlackIssuesMessageBuilder
88
from sentry.notifications.notifications.base import ProjectNotification
99
from sentry.services.hybrid_cloud.actor import RpcActor
@@ -21,7 +21,7 @@ def __init__(
2121
super().__init__(notification, context, recipient)
2222
self.notification: ProjectNotification = notification
2323

24-
def build(self) -> SlackAttachment | SlackBlock:
24+
def build(self) -> SlackBlock:
2525
group = getattr(self.notification, "group", None)
2626
return SlackIssuesMessageBuilder(
2727
group=group,

src/sentry/notifications/notifications/activity/release.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from sentry_relay.processing import parse_release
88

9-
from sentry import features
109
from sentry.models.activity import Activity
1110
from sentry.models.commit import Commit
1211
from sentry.models.commitfilechange import CommitFileChange
@@ -160,9 +159,7 @@ def get_message_actions(
160159
return [
161160
MessageAction(
162161
name=project.slug,
163-
label=project.slug
164-
if features.has("organizations:slack-block-kit", self.project.organization)
165-
else None,
162+
label=project.slug,
166163
url=self.organization.absolute_url(
167164
f"/organizations/{project.organization.slug}/releases/{release.version}/",
168165
query=f"project={project.id}&unselectedSeries=Healthy&referrer={self.metrics_key}&notification_uuid={self.notification_uuid}",

src/sentry/notifications/notifications/integration_nudge.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from collections.abc import Iterable, Mapping, MutableMapping, Sequence
66
from typing import TYPE_CHECKING, Any
77

8-
from sentry import features
98
from sentry.db.models import Model
109
from sentry.notifications.notifications.base import BaseNotification
1110
from sentry.notifications.utils.actions import MessageAction
@@ -85,9 +84,7 @@ def get_message_actions(
8584
return [
8685
MessageAction(
8786
name="Turn on personal notifications",
88-
label="Turn on personal notifications"
89-
if features.has("organizations:slack-block-kit", self.organization)
90-
else None,
87+
label="Turn on personal notifications",
9188
action_id="enable_notifications",
9289
value="all_slack",
9390
)

src/sentry/notifications/notifications/organization_request/abstract_invite_request.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from django.urls import reverse
88

9-
from sentry import features
109
from sentry.models.organizationmember import OrganizationMember
1110
from sentry.notifications.notifications.organization_request import OrganizationRequestNotification
1211
from sentry.notifications.notifications.strategies.member_write_role_recipient_strategy import (
@@ -71,22 +70,14 @@ def get_message_actions(
7170
style="primary",
7271
action_id="approve_request",
7372
value="approve_member",
74-
label=(
75-
"Approve"
76-
if features.has("organizations:slack-block-kit", self.organization)
77-
else None
78-
),
73+
label="Approve",
7974
),
8075
MessageAction(
8176
name="Reject",
8277
style="danger",
8378
action_id="approve_request",
8479
value="reject_member",
85-
label=(
86-
"Reject"
87-
if features.has("organizations:slack-block-kit", self.organization)
88-
else None
89-
),
80+
label="Reject",
9081
),
9182
MessageAction(
9283
name="See Members & Requests",

tests/sentry/api/endpoints/test_organization_join_request.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ def test_request_to_join_email_customer_domains(self):
175175
assert self.organization.absolute_url("/settings/members/") in mail.outbox[0].body
176176

177177
@responses.activate
178-
@with_feature("organizations:slack-block-kit")
179178
def test_request_to_join_slack(self):
180179
with self.tasks():
181180
self.get_success_response(self.organization.slug, email=self.email, status_code=204)

tests/sentry/integrations/slack/notifications/test_assigned.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from sentry.models.activity import Activity
77
from sentry.notifications.notifications.activity.assigned import AssignedActivityNotification
88
from sentry.testutils.cases import PerformanceIssueTestCase, SlackActivityNotificationTest
9-
from sentry.testutils.helpers.features import with_feature
109
from sentry.testutils.helpers.notifications import TEST_ISSUE_OCCURRENCE, TEST_PERF_ISSUE_OCCURRENCE
1110
from sentry.testutils.helpers.slack import get_blocks_and_fallback_text
1211
from sentry.testutils.skips import requires_snuba
@@ -112,7 +111,6 @@ def test_multiple_orgs(self):
112111
assert channel == self.identity.external_id
113112

114113
@responses.activate
115-
@with_feature("organizations:slack-block-kit")
116114
def test_assignment_block(self):
117115
"""
118116
Test that a Slack message is sent with the expected payload when an issue is assigned
@@ -139,7 +137,6 @@ def test_assignment_block(self):
139137
return_value=TEST_ISSUE_OCCURRENCE,
140138
new_callable=mock.PropertyMock,
141139
)
142-
@with_feature("organizations:slack-block-kit")
143140
def test_assignment_generic_issue_block(self, occurrence):
144141
"""
145142
Test that a Slack message is sent with the expected payload when a generic issue type is assigned
@@ -169,7 +166,6 @@ def test_assignment_generic_issue_block(self, occurrence):
169166
return_value=TEST_PERF_ISSUE_OCCURRENCE,
170167
new_callable=mock.PropertyMock,
171168
)
172-
@with_feature("organizations:slack-block-kit")
173169
def test_assignment_performance_issue_block(self, occurrence):
174170
"""
175171
Test that a Slack message is sent with the expected payload when a performance issue is assigned

tests/sentry/integrations/slack/notifications/test_regression.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from sentry.models.activity import Activity
66
from sentry.notifications.notifications.activity.regression import RegressionActivityNotification
77
from sentry.testutils.cases import PerformanceIssueTestCase, SlackActivityNotificationTest
8-
from sentry.testutils.helpers.features import with_feature
98
from sentry.testutils.helpers.notifications import TEST_ISSUE_OCCURRENCE, TEST_PERF_ISSUE_OCCURRENCE
109
from sentry.testutils.helpers.slack import get_blocks_and_fallback_text
1110
from sentry.testutils.skips import requires_snuba
@@ -27,7 +26,6 @@ def create_notification(self, group, data=None):
2726
)
2827

2928
@responses.activate
30-
@with_feature("organizations:slack-block-kit")
3129
def test_regression_block(self):
3230
"""
3331
Test that a Slack message is sent with the expected payload when an issue regresses
@@ -48,7 +46,6 @@ def test_regression_block(self):
4846
)
4947

5048
@responses.activate
51-
@with_feature("organizations:slack-block-kit")
5249
def test_regression_with_release_block(self):
5350
"""
5451
Test that a Slack message is sent with the expected payload when an issue regresses
@@ -77,7 +74,6 @@ def test_regression_with_release_block(self):
7774
return_value=TEST_PERF_ISSUE_OCCURRENCE,
7875
new_callable=mock.PropertyMock,
7976
)
80-
@with_feature("organizations:slack-block-kit")
8177
def test_regression_performance_issue_block(self, occurrence):
8278
"""
8379
Test that a Slack message is sent with the expected payload when a performance issue regresses
@@ -104,7 +100,6 @@ def test_regression_performance_issue_block(self, occurrence):
104100
return_value=TEST_ISSUE_OCCURRENCE,
105101
new_callable=mock.PropertyMock,
106102
)
107-
@with_feature("organizations:slack-block-kit")
108103
def test_regression_generic_issue_block(self, occurrence):
109104
"""
110105
Test that a Slack message is sent with the expected payload when a generic issue type regresses

tests/sentry/integrations/slack/notifications/test_resolved.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from sentry.models.activity import Activity
66
from sentry.notifications.notifications.activity.resolved import ResolvedActivityNotification
77
from sentry.testutils.cases import PerformanceIssueTestCase, SlackActivityNotificationTest
8-
from sentry.testutils.helpers.features import with_feature
98
from sentry.testutils.helpers.notifications import TEST_ISSUE_OCCURRENCE, TEST_PERF_ISSUE_OCCURRENCE
109
from sentry.testutils.helpers.slack import get_blocks_and_fallback_text
1110
from sentry.testutils.skips import requires_snuba
@@ -27,7 +26,6 @@ def create_notification(self, group):
2726
)
2827

2928
@responses.activate
30-
@with_feature("organizations:slack-block-kit")
3129
def test_resolved_block(self):
3230
"""
3331
Test that a Slack message is sent with the expected payload when an issue is resolved
@@ -61,7 +59,6 @@ def test_resolved_block(self):
6159
return_value=TEST_PERF_ISSUE_OCCURRENCE,
6260
new_callable=mock.PropertyMock,
6361
)
64-
@with_feature("organizations:slack-block-kit")
6562
def test_resolved_performance_issue_block(self, occurrence):
6663
"""
6764
Test that a Slack message is sent with the expected payload when a performance issue is resolved
@@ -92,7 +89,6 @@ def test_resolved_performance_issue_block(self, occurrence):
9289
return_value=TEST_ISSUE_OCCURRENCE,
9390
new_callable=mock.PropertyMock,
9491
)
95-
@with_feature("organizations:slack-block-kit")
9692
def test_resolved_generic_issue_block(self, occurrence):
9793
"""
9894
Test that a Slack message is sent with the expected payload when a generic issue type is resolved

tests/sentry/integrations/slack/notifications/test_resolved_in_release.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
ResolvedInReleaseActivityNotification,
88
)
99
from sentry.testutils.cases import PerformanceIssueTestCase, SlackActivityNotificationTest
10-
from sentry.testutils.helpers.features import with_feature
1110
from sentry.testutils.helpers.notifications import TEST_ISSUE_OCCURRENCE, TEST_PERF_ISSUE_OCCURRENCE
1211
from sentry.testutils.helpers.slack import get_blocks_and_fallback_text
1312
from sentry.testutils.skips import requires_snuba
@@ -31,7 +30,6 @@ def create_notification(self, group, version="meow"):
3130
)
3231

3332
@responses.activate
34-
@with_feature("organizations:slack-block-kit")
3533
def test_resolved_in_release_block(self):
3634
notification = self.create_notification(self.group)
3735
with self.tasks():
@@ -57,7 +55,6 @@ def test_resolved_in_release_block(self):
5755
return_value=TEST_PERF_ISSUE_OCCURRENCE,
5856
new_callable=mock.PropertyMock,
5957
)
60-
@with_feature("organizations:slack-block-kit")
6158
def test_resolved_in_release_performance_issue_block(self, occurrence):
6259
"""
6360
Test that a Slack message is sent with the expected payload when a performance issue is resolved in a release
@@ -86,7 +83,6 @@ def test_resolved_in_release_performance_issue_block(self, occurrence):
8683
return_value=TEST_ISSUE_OCCURRENCE,
8784
new_callable=mock.PropertyMock,
8885
)
89-
@with_feature("organizations:slack-block-kit")
9086
def test_resolved_in_release_generic_issue_block(self, occurrence):
9187
"""
9288
Test that a Slack message is sent with the expected payload when a generic issue type is resolved in a release
@@ -113,7 +109,6 @@ def test_resolved_in_release_generic_issue_block(self, occurrence):
113109
)
114110

115111
@responses.activate
116-
@with_feature("organizations:slack-block-kit")
117112
def test_resolved_in_release_parsed_version_block(self):
118113
"""
119114
Test that the release version is formatted to the short version when block kit is enabled.

0 commit comments

Comments
 (0)