Browse Source

ref(slack): Move View Replays to footer in block kit (#64794)

Moves the View Replays link to the footer instead of keeping it in the
rich text block (otherwise it gets code formatted and is not
hyperlinked).

<img width="392" alt="image"
src="https://github.com/getsentry/sentry/assets/45607721/7c7e189c-1c58-4317-b810-b39c08e36286">
Isabella Enriquez 1 year ago
parent
commit
ab4723b77d

+ 1 - 1
src/sentry/integrations/message_builder.py

@@ -166,7 +166,7 @@ def build_attachment_replay_link(
         referrer = EXTERNAL_PROVIDERS[ExternalProviders.SLACK]
         replay_url = f"{group.get_absolute_url()}replays/?referrer={referrer}"
 
-        return f"\n\n{url_format.format(text='View Replays', url=absolute_uri(replay_url))}"
+        return f"{url_format.format(text='View Replays', url=absolute_uri(replay_url))}"
 
     return None
 

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

@@ -548,7 +548,7 @@ class SlackIssuesMessageBuilder(BlockSlackMessageBuilder):
                 text = escape_slack_text(text)
 
         # This link does not contain user input (it's a static label and a url), must not escape it.
-        text += build_attachment_replay_link(self.group, self.event) or ""
+        replay_link = build_attachment_replay_link(self.group, self.event)
         project = Project.objects.get_from_cache(id=self.group.project_id)
 
         # If an event is unspecified, use the tags of the latest event (if one exists).
@@ -589,6 +589,8 @@ class SlackIssuesMessageBuilder(BlockSlackMessageBuilder):
         title = build_attachment_title(obj)
 
         if not features.has("organizations:slack-block-kit", self.group.project.organization):
+            if replay_link:
+                text += f"\n\n{replay_link}"
             if action_text and self.identity:
                 text += "\n" + action_text
 
@@ -713,7 +715,10 @@ class SlackIssuesMessageBuilder(BlockSlackMessageBuilder):
             for k, v in footer_data.items():
                 footer_text += f"{k}: {v}    "
 
-            footer_text = footer_text[:-4]  # chop off the empty space
+            if replay_link:
+                footer_text += replay_link
+            else:
+                footer_text = footer_text[:-4]  # chop off the empty space
             blocks.append(self.get_context_block(text=footer_text))
         else:
             blocks.append(self.get_context_block(text=footer, timestamp=timestamp))

+ 2 - 2
tests/sentry/integrations/slack/test_message_builder.py

@@ -948,8 +948,8 @@ class BuildGroupAttachmentReplaysTest(TestCase):
             blocks = SlackIssuesMessageBuilder(event.group, event.for_group(event.group)).build()
         assert isinstance(blocks, dict)
         assert (
-            f"\n\n<http://testserver/organizations/baz/issues/{event.group.id}/replays/?referrer=slack|View Replays>"
-            in blocks["blocks"][1]["elements"][0]["elements"][0]["text"]
+            f"<http://testserver/organizations/baz/issues/{event.group.id}/replays/?referrer=slack|View Replays>"
+            in blocks["blocks"][4]["elements"][0]["text"]
         )