2021-12-08 17:48:24 +00:00
|
|
|
const fs = require( 'fs' );
|
|
|
|
const path = require( 'path' );
|
|
|
|
|
2022-01-25 20:13:18 +00:00
|
|
|
const resultsFile = path.resolve( __dirname, '../test-results.json' );
|
2021-12-08 17:48:24 +00:00
|
|
|
|
|
|
|
const buildOutput = ( results ) => {
|
|
|
|
const { TITLE, SMOKE_TEST_URL } = process.env;
|
2022-01-25 16:41:28 +00:00
|
|
|
const resultKeys = Object.keys( results );
|
2021-12-08 17:48:24 +00:00
|
|
|
|
|
|
|
let output = `## ${ TITLE }:\n\n`;
|
|
|
|
output += `**Test URL:** ${ SMOKE_TEST_URL }\n`;
|
2022-01-25 16:41:28 +00:00
|
|
|
|
|
|
|
resultKeys.forEach( ( key ) => {
|
|
|
|
// The keys that we care about all start with 'num'
|
|
|
|
if ( key.includes( 'num' ) ) {
|
|
|
|
// match only capitalized words
|
|
|
|
const words = key.match( /[A-Z][a-z]+/g );
|
|
|
|
|
|
|
|
output += `**Total Number of ${ words.join( ' ' ) }:** ${
|
|
|
|
results[ key ]
|
|
|
|
}\n`;
|
|
|
|
}
|
|
|
|
} );
|
2021-12-08 17:48:24 +00:00
|
|
|
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = async ( { github, context } ) => {
|
|
|
|
let output = '';
|
|
|
|
|
|
|
|
if ( fs.existsSync( resultsFile ) ) {
|
|
|
|
const data = fs.readFileSync( resultsFile );
|
|
|
|
const results = JSON.parse( data );
|
|
|
|
|
|
|
|
output = buildOutput( results );
|
|
|
|
} else {
|
2022-01-24 15:22:29 +00:00
|
|
|
output = `## Test Results Not Found! \n\n`;
|
2022-02-01 18:27:25 +00:00
|
|
|
output += 'The path to the `test-results.json` file may need to be updated.';
|
2021-12-08 17:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await github.rest.issues.createComment( {
|
|
|
|
issue_number: context.issue.number,
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
body: output,
|
|
|
|
} );
|
|
|
|
};
|