More slack message formatting changes

This commit is contained in:
Rodel Calasagsag 2023-08-17 08:51:49 +08:00
parent dbbb2fb6ca
commit 0d6f1969ed
1 changed files with 93 additions and 65 deletions

View File

@ -4,6 +4,7 @@ module.exports = ( { core } ) => {
E2E_RESULT,
k6_RESULT,
PLUGINS_BLOCKS_PATH,
GITHUB_REF_NAME,
GITHUB_RUN_ID,
} = process.env;
const {
@ -11,82 +12,109 @@ module.exports = ( { core } ) => {
readContextBlocksFromJsonFiles,
} = require( './utils' );
const block_header = {
type: 'header',
text: {
type: 'plain_text',
text: 'Daily test results',
emoji: true,
},
const create_blockGroup_header = () => {
const date = new Intl.DateTimeFormat( 'en-US', {
dateStyle: 'full',
} ).format( Date.now() );
const block = [
{
type: 'divider',
},
{
type: 'header',
text: {
type: 'plain_text',
text: 'Daily test results',
emoji: true,
},
},
,
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `*Date:* ${ date }`,
},
],
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `*Branch:* \`${ GITHUB_REF_NAME }\``,
},
],
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `*GitHub run logs:* <https://github.com/woocommerce/woocommerce/actions/runs/${ GITHUB_RUN_ID }|${ GITHUB_RUN_ID }>`,
},
],
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: '*Test reports dashboard:* <https://woocommerce.github.io/woocommerce-test-reports/daily/|Daily smoke tests>',
},
],
},
{
type: 'divider',
},
];
return block;
};
const emoji_API = selectEmoji( API_RESULT );
const emoji_E2E = selectEmoji( E2E_RESULT );
const emoji_k6 = selectEmoji( k6_RESULT );
const blockGroup_nightlySite = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: '*Smoke tests on daily build*',
},
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `API ${ emoji_API }\tE2E ${ emoji_E2E }\tk6 ${ emoji_k6 }`,
},
],
},
{
type: 'divider',
},
];
const create_blockGroup_nightlySite = () => {
const emoji_API = selectEmoji( API_RESULT );
const emoji_E2E = selectEmoji( E2E_RESULT );
const emoji_k6 = selectEmoji( k6_RESULT );
const block = [
{
type: 'section',
text: {
type: 'mrkdwn',
text: '*Smoke tests on daily build*',
},
},
{
type: 'context',
elements: [
{
type: 'mrkdwn',
text: `API ${ emoji_API }\tE2E ${ emoji_E2E }\tk6 ${ emoji_k6 }`,
},
],
},
{
type: 'divider',
},
];
return block;
};
const blockGroup_header = create_blockGroup_header();
const blockGroup_nightlySite = create_blockGroup_nightlySite();
const blockGroups_plugins =
readContextBlocksFromJsonFiles( PLUGINS_BLOCKS_PATH );
const block_github = {
type: 'actions',
elements: [
{
type: 'button',
text: {
type: 'plain_text',
text: 'View GitHub run logs :github:',
emoji: true,
},
url: `https://github.com/woocommerce/woocommerce/actions/runs/${ GITHUB_RUN_ID }`,
},
],
};
const block_dashboard = {
type: 'actions',
elements: [
{
type: 'button',
text: {
type: 'plain_text',
text: 'Open test reports dashboard :colorful-bar-chart:',
emoji: true,
},
url: 'https://woocommerce.github.io/woocommerce-test-reports/daily/',
},
],
};
const payload = {
blocks: [
block_header,
...blockGroup_header,
...blockGroup_nightlySite,
...blockGroups_plugins.flat(),
block_github,
block_dashboard,
],
};
const payload_stringified = JSON.stringify( payload );
core.setOutput( 'payload', payload_stringified );