Skip to content

Commit

Permalink
E2E tests: mention users in Slack based on report name and branch name (
Browse files Browse the repository at this point in the history
#20964)

* Mention users in Slack based on configured report names and branch names

* Config updates of Slack handles

* Error handling - send notification event is mentions handling fails
  • Loading branch information
adimoldovan authored Sep 6, 2021
1 parent e42a4a4 commit 365f1f5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: enhancement

E2E tests: support user mentions in Slack based on report name and branch name
53 changes: 34 additions & 19 deletions projects/plugins/jetpack/tests/e2e/bin/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,26 +326,41 @@ function buildDefaultMessage( isSuccess, forceHeaderText = undefined ) {
},
];

if ( ! gh.pr && ! isSuccess && gh.branch.name === config.get( 'repository.mainBranch' ) ) {
const mentions = config
.get( 'slack.mentions' )
.map( function ( userId ) {
return ` <@${ userId }>`;
} )
.join( ' ' );

blocks.push(
{
type: 'section',
text: {
type: 'mrkdwn',
text: `cc ${ mentions }`,
},
},
{
type: 'divider',
// mention interested parties
try {
let handles = [];

for ( const branchEntry of config.get( 'slack.mentions.branches' ) ) {
if ( gh.branch.name === branchEntry.name ) {
handles = handles.concat( branchEntry.users );
}
);
}

for ( const reportEntry of config.get( 'slack.mentions.reports' ) ) {
if ( yargs.argv.report === reportEntry.name ) {
handles = handles.concat( reportEntry.users );
}
}

if ( handles.length > 0 && ! isSuccess ) {
// Create a single string of unique Slack handles
const mentions = [ ...new Set( handles ) ].join( ' ' );

blocks.push(
{
type: 'section',
text: {
type: 'mrkdwn',
text: `cc ${ mentions }`,
},
},
{
type: 'divider',
}
);
}
} catch ( error ) {
console.log( `ERROR: ${ error }` );
}

return blocks;
Expand Down
Binary file modified projects/plugins/jetpack/tests/e2e/config/encrypted.enc
Binary file not shown.

0 comments on commit 365f1f5

Please sign in to comment.