From ccd7cf2e34852dd4625f53476a1d9c11c9b39938 Mon Sep 17 00:00:00 2001 From: Gabriel Dugny Date: Fri, 27 Sep 2024 12:17:03 +0200 Subject: [PATCH] fix(slack): display edits in Slack update --- .../slack/messages/slack_messages.py | 86 ++++++++++++------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/src/firefighter/slack/messages/slack_messages.py b/src/firefighter/slack/messages/slack_messages.py index f2453386..9b57ea8a 100644 --- a/src/firefighter/slack/messages/slack_messages.py +++ b/src/firefighter/slack/messages/slack_messages.py @@ -359,18 +359,20 @@ def get_blocks(self) -> list[Block]: if len(fields) == 0: fields.append("_No changes detected._") - blocks.extend([ - DividerBlock(), - SectionBlock( - block_id="message_role_update", - fields=fields, - accessory=ButtonElement( - text="Update", - value=str(self.incident.id), - action_id=UpdateRolesModal.open_action, + blocks.extend( + [ + DividerBlock(), + SectionBlock( + block_id="message_role_update", + fields=fields, + accessory=ButtonElement( + text="Update", + value=str(self.incident.id), + action_id=UpdateRolesModal.open_action, + ), ), - ), - ]) + ] + ) if not self.first_update: blocks.append( ContextBlock( @@ -457,6 +459,16 @@ def get_blocks(self) -> list[Block]: blocks.append( slack_block_quote(self.incident_update.message), ) + if self.incident_update.title and self.incident_update.title != "": + blocks.append( + SectionBlock( + text=f"New title: *{shorten(self.incident_update.title, 2985)}*" + ), + ) + if self.incident_update.description and self.incident_update.description != "": + blocks.append( + slack_block_quote(self.incident_update.description), + ) fields = [] if self.in_channel: if self.incident_update.status: @@ -477,24 +489,32 @@ def get_blocks(self) -> list[Block]: text=f":package: *Component:* {self.incident.component.group.name} - {self.incident.component.name}" ) ) + if self.incident_update.environment: + fields.append( + MarkdownTextObject( + text=f":round_pushpin: *Environment:* {self.incident_update.environment.value}" + ) + ) if len(fields) > 0: - blocks.extend([ - DividerBlock(), - SectionBlock( - block_id="message_status_update", - fields=fields, - accessory=( - ButtonElement( - text="Update", - value=str(self.incident.id), - action_id=UpdateStatusModal.open_action, - ) - if self.in_channel - else None + blocks.extend( + [ + DividerBlock(), + SectionBlock( + block_id="message_status_update", + fields=fields, + accessory=( + ButtonElement( + text="Update", + value=str(self.incident.id), + action_id=UpdateStatusModal.open_action, + ) + if self.in_channel + else None + ), ), - ), - ]) + ] + ) if self.incident_update.created_by: blocks.append( @@ -683,13 +703,15 @@ def get_blocks(self) -> list[Block]: ] if self.incident.status >= IncidentStatus.FIXED: - blocks.extend([ - SectionBlock( - text=MarkdownTextObject( - text=f":white_check_mark: *UPDATE*: Incident #{self.incident.conversation.name} has been mitigated, you can resume your deployments." + blocks.extend( + [ + SectionBlock( + text=MarkdownTextObject( + text=f":white_check_mark: *UPDATE*: Incident #{self.incident.conversation.name} has been mitigated, you can resume your deployments." + ) ) - ) - ]) + ] + ) return blocks def get_text(self) -> str: