Browse Source

chore(slack): remove more non-block kit (#68997)

Cathy Teng 10 months ago
parent
commit
10f9c3faa2

+ 2 - 47
src/sentry/integrations/slack/message_builder/base/base.py

@@ -1,15 +1,13 @@
 from __future__ import annotations
 
 from abc import ABC
-from collections.abc import Mapping, MutableMapping, Sequence
+from collections.abc import Mapping, MutableMapping
 from typing import Any
 
 from sentry.eventstore.models import Event, GroupEvent
-from sentry.integrations.slack.message_builder import LEVEL_TO_COLOR, SlackAttachment, SlackBody
+from sentry.integrations.slack.message_builder import SlackBody
 from sentry.models.group import Group
 from sentry.notifications.utils.actions import MessageAction
-from sentry.utils.assets import get_asset_url
-from sentry.utils.http import absolute_uri
 
 
 def get_slack_button(action: MessageAction) -> Mapping[str, Any]:
@@ -49,46 +47,3 @@ class SlackMessageBuilder(ABC):
         Returns True if we need to escape the text in the message.
         """
         return False
-
-    def _build(
-        self,
-        text: str,
-        title: str | None = None,
-        title_link: str | None = None,
-        footer: str | None = None,
-        color: str | None = None,
-        actions: Sequence[MessageAction] | None = None,
-        **kwargs: Any,
-    ) -> SlackAttachment:
-        """
-        Helper to DRY up Slack specific fields.
-
-        :param string text: Body text.
-        :param [string] title: Title text.
-        :param [string] title_link: Optional URL attached to the title.
-        :param [string] footer: Footer text.
-        :param [string] color: The key in the Slack palate table, NOT hex. Default: "info".
-        :param [list[MessageAction]] actions: List of actions displayed alongside the message.
-        :param kwargs: Everything else.
-        """
-        # If `footer` string is passed, automatically attach a `footer_icon`.
-        if footer:
-            kwargs["footer"] = footer
-            kwargs["footer_icon"] = str(
-                absolute_uri(get_asset_url("sentry", "images/sentry-email-avatar.png"))
-            )
-
-        if title:
-            kwargs["title"] = title
-            if title_link:
-                kwargs["title_link"] = title_link
-
-        if actions is not None:
-            kwargs["actions"] = [get_slack_button(action) for action in actions]
-
-        return {
-            "text": text,
-            "mrkdwn_in": ["text"],
-            "color": LEVEL_TO_COLOR[color or "info"],
-            **kwargs,
-        }

+ 1 - 2
src/sentry/integrations/slack/message_builder/issues.py

@@ -28,7 +28,6 @@ from sentry.integrations.slack.message_builder import (
     CATEGORY_TO_EMOJI,
     LEVEL_TO_EMOJI,
     SLACK_URL_FORMAT,
-    SlackAttachment,
     SlackBlock,
 )
 from sentry.integrations.slack.message_builder.base.block import BlockSlackMessageBuilder
@@ -506,7 +505,7 @@ class SlackIssuesMessageBuilder(BlockSlackMessageBuilder):
         """
         return True
 
-    def build(self, notification_uuid: str | None = None) -> SlackBlock | SlackAttachment:
+    def build(self, notification_uuid: str | None = None) -> SlackBlock:
         # XXX(dcramer): options are limited to 100 choices, even when nested
         text = build_attachment_text(self.group, self.event) or ""
         text = text.strip(" \n")

+ 2 - 12
src/sentry/integrations/slack/message_builder/notifications/base.py

@@ -3,8 +3,7 @@ from __future__ import annotations
 from collections.abc import Mapping
 from typing import Any
 
-from sentry import features
-from sentry.integrations.slack.message_builder import SlackAttachment, SlackBlock
+from sentry.integrations.slack.message_builder import SlackBlock
 from sentry.integrations.slack.message_builder.base.block import BlockSlackMessageBuilder
 from sentry.integrations.slack.utils.escape import escape_slack_text
 from sentry.notifications.notifications.base import BaseNotification
@@ -25,7 +24,7 @@ class SlackNotificationsMessageBuilder(BlockSlackMessageBuilder):
         self.context = context
         self.recipient = recipient
 
-    def build(self) -> SlackAttachment | SlackBlock:
+    def build(self) -> SlackBlock:
         callback_id_raw = self.notification.get_callback_data()
         title = self.notification.build_attachment_title(self.recipient)
         title_link = self.notification.get_title_link(self.recipient, ExternalProviders.SLACK)
@@ -35,15 +34,6 @@ class SlackNotificationsMessageBuilder(BlockSlackMessageBuilder):
         )
         actions = self.notification.get_message_actions(self.recipient, ExternalProviders.SLACK)
         callback_id = json.dumps(callback_id_raw) if callback_id_raw else None
-        if not features.has("organizations:slack-block-kit", self.notification.organization):
-            return self._build(
-                title=title,
-                title_link=title_link,
-                text=text,
-                footer=footer,
-                actions=actions,
-                callback_id=callback_id,
-            )
 
         first_block_text = ""
         if title_link:

+ 2 - 15
src/sentry/integrations/slack/message_builder/notifications/digest.py

@@ -3,10 +3,9 @@ from __future__ import annotations
 from collections.abc import Mapping
 from typing import Any
 
-from sentry import features
 from sentry.digests import Digest
 from sentry.digests.utils import get_groups
-from sentry.integrations.slack.message_builder import SlackAttachment, SlackBlock
+from sentry.integrations.slack.message_builder import SlackBlock
 from sentry.integrations.slack.message_builder.issues import SlackIssuesMessageBuilder
 from sentry.notifications.notifications.digest import DigestNotification
 from sentry.services.hybrid_cloud.actor import RpcActor
@@ -24,25 +23,13 @@ class DigestNotificationMessageBuilder(SlackNotificationsMessageBuilder):
         super().__init__(notification, context, recipient)
         self.notification: DigestNotification = notification
 
-    def build(self) -> SlackAttachment | SlackBlock:
+    def build(self) -> SlackBlock:
         """
         It's currently impossible in mypy to have recursive types so we need a
         hack to get this to return a SlackBody.
         """
         digest: Digest = self.context.get("digest", {})
         digest_groups = get_groups(digest)
-        if not features.has("organizations:slack-block-kit", self.notification.organization):
-            return [
-                SlackIssuesMessageBuilder(
-                    group=group,
-                    event=event,
-                    rules=[rule],
-                    issue_details=True,
-                    notification=self.notification,
-                    recipient=self.recipient,
-                ).build()
-                for rule, group, event in digest_groups
-            ]
         blocks = []
         for rule, group, event in digest_groups:
             alert_as_blocks = SlackIssuesMessageBuilder(

+ 2 - 2
src/sentry/integrations/slack/message_builder/notifications/issues.py

@@ -3,7 +3,7 @@ from __future__ import annotations
 from collections.abc import Mapping
 from typing import Any
 
-from sentry.integrations.slack.message_builder import SlackAttachment, SlackBlock
+from sentry.integrations.slack.message_builder import SlackBlock
 from sentry.integrations.slack.message_builder.issues import SlackIssuesMessageBuilder
 from sentry.notifications.notifications.base import ProjectNotification
 from sentry.services.hybrid_cloud.actor import RpcActor
@@ -21,7 +21,7 @@ class IssueNotificationMessageBuilder(SlackNotificationsMessageBuilder):
         super().__init__(notification, context, recipient)
         self.notification: ProjectNotification = notification
 
-    def build(self) -> SlackAttachment | SlackBlock:
+    def build(self) -> SlackBlock:
         group = getattr(self.notification, "group", None)
         return SlackIssuesMessageBuilder(
             group=group,

+ 1 - 4
src/sentry/notifications/notifications/activity/release.py

@@ -6,7 +6,6 @@ from urllib.parse import urlencode
 
 from sentry_relay.processing import parse_release
 
-from sentry import features
 from sentry.models.activity import Activity
 from sentry.models.commit import Commit
 from sentry.models.commitfilechange import CommitFileChange
@@ -160,9 +159,7 @@ class ReleaseActivityNotification(ActivityNotification):
                 return [
                     MessageAction(
                         name=project.slug,
-                        label=project.slug
-                        if features.has("organizations:slack-block-kit", self.project.organization)
-                        else None,
+                        label=project.slug,
                         url=self.organization.absolute_url(
                             f"/organizations/{project.organization.slug}/releases/{release.version}/",
                             query=f"project={project.id}&unselectedSeries=Healthy&referrer={self.metrics_key}&notification_uuid={self.notification_uuid}",

+ 1 - 4
src/sentry/notifications/notifications/integration_nudge.py

@@ -5,7 +5,6 @@ import random
 from collections.abc import Iterable, Mapping, MutableMapping, Sequence
 from typing import TYPE_CHECKING, Any
 
-from sentry import features
 from sentry.db.models import Model
 from sentry.notifications.notifications.base import BaseNotification
 from sentry.notifications.utils.actions import MessageAction
@@ -85,9 +84,7 @@ class IntegrationNudgeNotification(BaseNotification):
         return [
             MessageAction(
                 name="Turn on personal notifications",
-                label="Turn on personal notifications"
-                if features.has("organizations:slack-block-kit", self.organization)
-                else None,
+                label="Turn on personal notifications",
                 action_id="enable_notifications",
                 value="all_slack",
             )

+ 2 - 11
src/sentry/notifications/notifications/organization_request/abstract_invite_request.py

@@ -6,7 +6,6 @@ from typing import TYPE_CHECKING, Any
 
 from django.urls import reverse
 
-from sentry import features
 from sentry.models.organizationmember import OrganizationMember
 from sentry.notifications.notifications.organization_request import OrganizationRequestNotification
 from sentry.notifications.notifications.strategies.member_write_role_recipient_strategy import (
@@ -71,22 +70,14 @@ class AbstractInviteRequestNotification(OrganizationRequestNotification, abc.ABC
                 style="primary",
                 action_id="approve_request",
                 value="approve_member",
-                label=(
-                    "Approve"
-                    if features.has("organizations:slack-block-kit", self.organization)
-                    else None
-                ),
+                label="Approve",
             ),
             MessageAction(
                 name="Reject",
                 style="danger",
                 action_id="approve_request",
                 value="reject_member",
-                label=(
-                    "Reject"
-                    if features.has("organizations:slack-block-kit", self.organization)
-                    else None
-                ),
+                label="Reject",
             ),
             MessageAction(
                 name="See Members & Requests",

+ 0 - 1
tests/sentry/api/endpoints/test_organization_join_request.py

@@ -175,7 +175,6 @@ class OrganizationJoinRequestTest(APITestCase, SlackActivityNotificationTest, Hy
         assert self.organization.absolute_url("/settings/members/") in mail.outbox[0].body
 
     @responses.activate
-    @with_feature("organizations:slack-block-kit")
     def test_request_to_join_slack(self):
         with self.tasks():
             self.get_success_response(self.organization.slug, email=self.email, status_code=204)

+ 0 - 4
tests/sentry/integrations/slack/notifications/test_assigned.py

@@ -6,7 +6,6 @@ import responses
 from sentry.models.activity import Activity
 from sentry.notifications.notifications.activity.assigned import AssignedActivityNotification
 from sentry.testutils.cases import PerformanceIssueTestCase, SlackActivityNotificationTest
-from sentry.testutils.helpers.features import with_feature
 from sentry.testutils.helpers.notifications import TEST_ISSUE_OCCURRENCE, TEST_PERF_ISSUE_OCCURRENCE
 from sentry.testutils.helpers.slack import get_blocks_and_fallback_text
 from sentry.testutils.skips import requires_snuba
@@ -112,7 +111,6 @@ class SlackAssignedNotificationTest(SlackActivityNotificationTest, PerformanceIs
         assert channel == self.identity.external_id
 
     @responses.activate
-    @with_feature("organizations:slack-block-kit")
     def test_assignment_block(self):
         """
         Test that a Slack message is sent with the expected payload when an issue is assigned
@@ -139,7 +137,6 @@ class SlackAssignedNotificationTest(SlackActivityNotificationTest, PerformanceIs
         return_value=TEST_ISSUE_OCCURRENCE,
         new_callable=mock.PropertyMock,
     )
-    @with_feature("organizations:slack-block-kit")
     def test_assignment_generic_issue_block(self, occurrence):
         """
         Test that a Slack message is sent with the expected payload when a generic issue type is assigned
@@ -169,7 +166,6 @@ class SlackAssignedNotificationTest(SlackActivityNotificationTest, PerformanceIs
         return_value=TEST_PERF_ISSUE_OCCURRENCE,
         new_callable=mock.PropertyMock,
     )
-    @with_feature("organizations:slack-block-kit")
     def test_assignment_performance_issue_block(self, occurrence):
         """
         Test that a Slack message is sent with the expected payload when a performance issue is assigned

Some files were not shown because too many files changed in this diff