Skip to content

Commit

Permalink
Repo Gardening: log failures to send Slack messages
Browse files Browse the repository at this point in the history
Fixes #40366

Until now, we used to try to send messages to Slack, and didn't do anything if the message could not be sent. We'll now log the message, either by sending a Slack message to myself, or the Quality team for folks outside of the Automattic organization.

This will allow us to better detect triage Slack actions that could not be completed, because a team no longer exists and their Slack channel has been archived for example.
  • Loading branch information
jeherve committed Nov 27, 2024
1 parent b11c20a commit 34c2612
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Slack messaging: when a Slack message cannot be sent to a specific channel, send a message to warn about the issue.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,68 @@ async function sendSlackMessage( message, channel, payload, customMessageFormat
},
} );

// If the request failed, let's send a direct message to @jeherve about it, so we can investigate.
// For folks outside of Automattic, let's use the Quality team channel.
if ( ! slackRequest.ok ) {
const {
repository: { owner },
} = payload;
const { html_url, title } = payload?.pull_request ?? payload.issue;

const reportingChannel =
owner === 'automattic' ? 'D1KN8VCCA' : getInput( 'slack_quality_channel' );
if ( ! reportingChannel ) {
return false;
}
const reportMessage = {
channel: reportingChannel,
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Error sending message to Slack: ${ slackRequest.error }`,
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `<${ html_url }|${ title }>`,
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: 'Review',
emoji: true,
},
value: 'click_review',
url: `${ html_url }`,
action_id: 'button-action',
},
},
],
text: `Error sending message to Slack: -- <${ html_url }|${ title }>`, // Fallback text for display in notifications.
mrkdwn: true, // Formatting of the fallback text.
unfurl_links: false,
unfurl_media: false,
};
await fetch( 'https://slack.com/api/chat.postMessage', {
method: 'POST',
body: JSON.stringify( reportMessage ),
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': reportMessage.length,
Authorization: `Bearer ${ token }`,
Accept: 'application/json',
},
} );
}

return !! slackRequest.ok;
}

Expand Down

0 comments on commit 34c2612

Please sign in to comment.