From 4f107689736fad6ee6e1141baa3a054e400886f2 Mon Sep 17 00:00:00 2001 From: Brian Phillips <28457+brianphillips@users.noreply.github.com> Date: Fri, 25 Apr 2025 13:16:51 -0500 Subject: [PATCH] fix slack notification processor attachment blocks A `section` block requires that either a `text` or `fields` item be included. Since we were already defaulting the payload.description, this change simply ensures that the text portion of the block is specified (with tests updated accordingly). Signed-off-by: Brian Phillips <28457+brianphillips@users.noreply.github.com> --- .changeset/crazy-chefs-sin.md | 5 +++++ .../src/lib/SlackNotificationProcessor.test.ts | 8 ++++++++ .../notifications-backend-module-slack/src/lib/util.ts | 10 ++++------ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .changeset/crazy-chefs-sin.md diff --git a/.changeset/crazy-chefs-sin.md b/.changeset/crazy-chefs-sin.md new file mode 100644 index 0000000000..8d33add929 --- /dev/null +++ b/.changeset/crazy-chefs-sin.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-notifications-backend-module-slack': patch +--- + +Fix slack notification processor to handle a notification with an empty description diff --git a/plugins/notifications-backend-module-slack/src/lib/SlackNotificationProcessor.test.ts b/plugins/notifications-backend-module-slack/src/lib/SlackNotificationProcessor.test.ts index f5893ff456..3229c681c8 100644 --- a/plugins/notifications-backend-module-slack/src/lib/SlackNotificationProcessor.test.ts +++ b/plugins/notifications-backend-module-slack/src/lib/SlackNotificationProcessor.test.ts @@ -158,6 +158,10 @@ describe('SlackNotificationProcessor', () => { blocks: [ { type: 'section', + text: { + text: 'No description provided', + type: 'mrkdwn', + }, accessory: { type: 'button', text: { @@ -229,6 +233,10 @@ describe('SlackNotificationProcessor', () => { blocks: [ { type: 'section', + text: { + text: 'No description provided', + type: 'mrkdwn', + }, accessory: { type: 'button', text: { diff --git a/plugins/notifications-backend-module-slack/src/lib/util.ts b/plugins/notifications-backend-module-slack/src/lib/util.ts index 5e2adbeec5..2d3a03bd2c 100644 --- a/plugins/notifications-backend-module-slack/src/lib/util.ts +++ b/plugins/notifications-backend-module-slack/src/lib/util.ts @@ -46,12 +46,10 @@ export function toSlackBlockKit(payload: NotificationPayload): KnownBlock[] { return [ { type: 'section', - ...(description && { - text: { - type: 'mrkdwn', - text: description ?? 'No description provided', - }, - }), + text: { + type: 'mrkdwn', + text: description ?? 'No description provided', + }, accessory: { type: 'button', text: {