-
Notifications
You must be signed in to change notification settings - Fork 210
feat: add --slack-full-width for full-width Slack alerts with markdown test result tables #2107
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
base: master
Are you sure you want to change the base?
Changes from all commits
9b23738
fa34bca
153f530
117f19f
7d2a4ff
a611b9f
5ec85bb
3e54e29
5446b6b
1eb6672
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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,16 +26,36 @@ class SlackAlertMessageSchema(BaseModel): | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class SlackAlertMessageBuilder(SlackMessageBuilder): | ||||||||||||||||||||||||||||||
| def __init__(self) -> None: | ||||||||||||||||||||||||||||||
| def __init__(self, full_width: bool = False) -> None: | ||||||||||||||||||||||||||||||
| super().__init__() | ||||||||||||||||||||||||||||||
| self.full_width = full_width | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_slack_message( | ||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||
| alert_schema: SlackAlertMessageSchema, | ||||||||||||||||||||||||||||||
| ) -> SlackMessageSchema: | ||||||||||||||||||||||||||||||
| if self.full_width: | ||||||||||||||||||||||||||||||
| # A rich_text block at the start forces Slack to use full message width | ||||||||||||||||||||||||||||||
| # for following blocks instead of the narrower attachment-style layout. | ||||||||||||||||||||||||||||||
| # The elements array must be non-empty per Slack Block Kit API. | ||||||||||||||||||||||||||||||
| self._add_always_displayed_blocks( | ||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "type": "rich_text", | ||||||||||||||||||||||||||||||
| "elements": [ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "type": "rich_text_section", | ||||||||||||||||||||||||||||||
| "elements": [{"type": "text", "text": " "}], | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| self.add_title_to_slack_alert(alert_schema.title) | ||||||||||||||||||||||||||||||
| self.add_preview_to_slack_alert(alert_schema.preview) | ||||||||||||||||||||||||||||||
| self.add_details_to_slack_alert(alert_schema.details) | ||||||||||||||||||||||||||||||
| if self.full_width: | ||||||||||||||||||||||||||||||
| self.slack_message["attachments"] = [] | ||||||||||||||||||||||||||||||
| return super().get_slack_message() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def add_title_to_slack_alert(self, title_blocks: Optional[SlackBlocksType] = None): | ||||||||||||||||||||||||||||||
|
|
@@ -46,15 +66,23 @@ def add_title_to_slack_alert(self, title_blocks: Optional[SlackBlocksType] = Non | |||||||||||||||||||||||||||||
| def add_preview_to_slack_alert( | ||||||||||||||||||||||||||||||
| self, preview_blocks: Optional[SlackBlocksType] = None | ||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||
| if preview_blocks: | ||||||||||||||||||||||||||||||
| validated_preview_blocks = self._validate_preview_blocks(preview_blocks) | ||||||||||||||||||||||||||||||
| if not preview_blocks: | ||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||
| validated_preview_blocks = self._validate_preview_blocks(preview_blocks) | ||||||||||||||||||||||||||||||
| if self.full_width: | ||||||||||||||||||||||||||||||
| self._add_always_displayed_blocks(validated_preview_blocks) | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| self._add_blocks_as_attachments(validated_preview_blocks) | ||||||||||||||||||||||||||||||
|
Comment on lines
+69
to
75
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. Skip attachment-era preview validation in Line 71 still runs Suggested fix if not preview_blocks:
return
- validated_preview_blocks = self._validate_preview_blocks(preview_blocks)
if self.full_width:
- self._add_always_displayed_blocks(validated_preview_blocks)
+ self._add_always_displayed_blocks(preview_blocks)
else:
+ validated_preview_blocks = self._validate_preview_blocks(preview_blocks)
self._add_blocks_as_attachments(validated_preview_blocks)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def add_details_to_slack_alert( | ||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||
| detail_blocks: Optional[SlackBlocksType] = None, | ||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||
| if detail_blocks: | ||||||||||||||||||||||||||||||
| if not detail_blocks: | ||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||
| if self.full_width: | ||||||||||||||||||||||||||||||
| self._add_always_displayed_blocks(detail_blocks) | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| self._add_blocks_as_attachments(detail_blocks) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @classmethod | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.