Skip to content
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

Repo Gardening: update triage tasks (wording and Slack notifications) #29706

Merged
merged 8 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Triage tasks: update wording of messages and start warning folks of issues that do get any Priority label added automatically, so they can triage manually.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function formatSlackMessage( payload, channel, message ) {
const { issue, repository } = payload;
const { html_url, title } = issue;

let dris = '@bug_herders';
let dris = '@kitkat-team';
switch ( repository.full_name ) {
case 'Automattic/jetpack':
dris = '@jpop-da';
Expand All @@ -154,17 +154,7 @@ function formatSlackMessage( payload, channel, message ) {
type: 'section',
text: {
type: 'mrkdwn',
text: message,
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `${ dris } Could you take a look at it, re-prioritize and escalate if you think that's necessary, and mark this message as :done: once you've done so? Thank you!`,
text: `${ dris } ${ message }`,
},
},
{
Expand All @@ -176,20 +166,9 @@ function formatSlackMessage( payload, channel, message ) {
type: 'mrkdwn',
text: `<${ html_url }|${ title }>`,
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: 'View',
emoji: true,
},
value: 'click_review',
url: `${ html_url }`,
action_id: 'button-action',
},
},
],
text: `${ message } -- <${ html_url }|${ title }>`, // Fallback text for display in notifications.
text: `${ dris } ${ message } -- <${ html_url }|${ title }>`, // Fallback text for display in notifications.
mrkdwn: true, // Formatting of the fallback text.
unfurl_links: false,
unfurl_media: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
const { getInput } = require( '@actions/core' );
const debug = require( '../../utils/debug' );
const getLabels = require( '../../utils/get-labels' );
const sendSlackMessage = require( '../../utils/send-slack-message' );

/* global GitHub, WebhookPayloadIssue */

/**
* Check for a label showing that the Quality team was already notified.
*
* @param {GitHub} octokit - Initialized Octokit REST client.
* @param {string} owner - Repository owner.
* @param {string} repo - Repository name.
* @param {string} number - Issue number.
* @returns {Promise<boolean>} Promise resolving to boolean.
*/
async function hasKitkatSignalLabel( octokit, owner, repo, number ) {
const labels = await getLabels( octokit, owner, repo, number );

// Does the list of labels includes the "[Pri] TBD" label?
return labels.includes( '[Pri] TBD' );
}

/**
* Check for Priority label on an issue
*
Expand All @@ -14,8 +32,8 @@ const getLabels = require( '../../utils/get-labels' );
*/
async function hasPriorityLabels( octokit, owner, repo, number ) {
const labels = await getLabels( octokit, owner, repo, number );
// We're only interested in priority labels.
return !! labels.find( label => label.match( /^\[Pri\].*$/ ) );
// We're only interested in priority labels, but not if the label is [Pri] TBD.
return !! labels.find( label => label !== '[Pri] TBD' && label.match( /^\[Pri\].*$/ ) );
}

/**
Expand Down Expand Up @@ -93,6 +111,46 @@ function findPriority( body ) {
return null;
}

/**
* Build an object containing the slack message and its formatting to send to Slack.
*
* @param {WebhookPayloadIssue} payload - Issue event payload.
* @param {string} channel - Slack channel ID.
* @param {string} message - Basic message (without the formatting).
* @returns {object} Object containing the slack message and its formatting.
*/
function formatSlackMessage( payload, channel, message ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may want to extract this function into a helper that can be shared by the different tasks, since I have a few variations of it already.

const { issue } = payload;
const { html_url, title } = issue;

return {
channel,
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: message,
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `<${ html_url }|${ title }>`,
},
},
],
text: `${ message } -- <${ html_url }|${ title }>`, // Fallback text for display in notifications.
mrkdwn: true, // Formatting of the fallback text.
unfurl_links: false,
unfurl_media: false,
};
}

/**
* Add labels to newly opened issues.
*
Expand Down Expand Up @@ -148,6 +206,50 @@ async function triageNewIssues( payload, octokit ) {
issue_number: number,
labels: [ `[Pri] ${ priority }` ],
} );
} else if ( priority === null && ! hasPriorityLabel ) {
// No priority found, and no priority label.
// Let's notify the team so they can prioritize the issue appropriately.
// So far only enabled in the Calypso repo.
if ( 'Automattic/wp-calypso' !== repository.full_name ) {
return;
}

// No Slack tokens, we won't be able to escalate. Bail.
const slackToken = getInput( 'slack_token' );
const channel = getInput( 'slack_quality_channel' );
if ( ! slackToken || ! channel ) {
jeherve marked this conversation as resolved.
Show resolved Hide resolved
debug(
`triage-new-issues: No Slack token or channel found. Not sending any Slack notification for #${ number }.`
);
return null;
}

// Check if Kitkat input was already requested for that issue.
const hasBeenRequested = await hasKitkatSignalLabel( octokit, ownerLogin, name, number );
if ( hasBeenRequested ) {
debug(
`triage-new-issues: Kitkat input was already requested for issue #${ number }. Aborting.`
);
return;
}

debug(
`triage-new-issues: #${ number } doesn't have a Priority set. Sending in Slack message to the Kitkat team.`
);

const message = '@kitkat-team New bug missing priority. Please do a priority assessment.';
const slackMessageFormat = formatSlackMessage( payload, channel, message );
await sendSlackMessage( message, channel, slackToken, payload, slackMessageFormat );
jeherve marked this conversation as resolved.
Show resolved Hide resolved

debug(
`triage-new-issues: Adding a label to issue #${ number } to show that Kitkat was warned.`
);
await octokit.rest.issues.addLabels( {
owner: ownerLogin,
repo: name,
issue_number: number,
labels: [ '[Pri] TBD' ],
} );
}
}

Expand Down