From e80279132b892045439f8f990c7ab23c0aba747a Mon Sep 17 00:00:00 2001 From: Carter Medlin Date: Wed, 1 Dec 2021 11:23:37 -0800 Subject: [PATCH 1/3] Improving slack output display --- WordpressSync/index.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/WordpressSync/index.js b/WordpressSync/index.js index b8eacf6..a7abc21 100644 --- a/WordpressSync/index.js +++ b/WordpressSync/index.js @@ -91,9 +91,13 @@ const doProcessEndpoints = async work => { if (endpoint.ReportingChannel_Slack && slackBotGetToken()) { //Endpoint reporting channel enabled. Add a post for each commit report. if (commitReports?.length) { + let opCount = 0; + /** @type {string[]} */ let mergeFileNames = []; - commitReports.map(x => { + commitReports.forEach(x => { + opCount += x.Files.length; + mergeFileNames.push( ...x.Files.map( //Remove file extension, and remove resolution postfix @@ -113,9 +117,14 @@ const doProcessEndpoints = async work => { { username: endpoint.name } ); - const allfileNames = [...new Set(mergeFileNames)]; + const slugs = [...new Set(mergeFileNames)]; + + let slackMessage = `${opCount} changes. _${slugs.join(", ")}_`; + if (slackMessage.length > 300) { + slackMessage = `${opCount} changes.`; + } - await slackBot.Chat(`_${allfileNames.join(", ")}_`); + await slackBot.Chat(slackMessage); for (const commitReport of commitReports) { const fileData = commitReport.Files.map( @@ -123,7 +132,13 @@ const doProcessEndpoints = async work => { ).join("\n"); await slackBot.Reply( - `<${commitReport.Commit.html_url}|${commitReport.Commit.message}>\n${fileData}` + `<${commitReport.Commit.html_url}|${ + commitReport.Commit.message + }>\n${ + commitReport.Files.length > 1 + ? `${commitReport.Files.length} changes\n` + : "" + }${fileData}` ); } } From b93fcf4e2828a4f270e2197da2dc0591ccecabae Mon Sep 17 00:00:00 2001 From: Carter Medlin Date: Wed, 1 Dec 2021 11:29:53 -0800 Subject: [PATCH 2/3] simplify logic --- WordpressSync/index.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/WordpressSync/index.js b/WordpressSync/index.js index a7abc21..f5e0868 100644 --- a/WordpressSync/index.js +++ b/WordpressSync/index.js @@ -117,14 +117,11 @@ const doProcessEndpoints = async work => { { username: endpoint.name } ); - const slugs = [...new Set(mergeFileNames)]; + const slugList = ` _${[...new Set(mergeFileNames)].join(", ")}_`; - let slackMessage = `${opCount} changes. _${slugs.join(", ")}_`; - if (slackMessage.length > 300) { - slackMessage = `${opCount} changes.`; - } - - await slackBot.Chat(slackMessage); + await slackBot.Chat( + `${opCount} changes.${slugList.length < 300 ? slugList : ""}` + ); for (const commitReport of commitReports) { const fileData = commitReport.Files.map( From 5eabe063ce42d5864cfea0242739b8a9e906e291 Mon Sep 17 00:00:00 2001 From: Carter Medlin Date: Wed, 1 Dec 2021 11:39:13 -0800 Subject: [PATCH 3/3] colons when displaying inline --- WordpressSync/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordpressSync/index.js b/WordpressSync/index.js index f5e0868..3bb47b3 100644 --- a/WordpressSync/index.js +++ b/WordpressSync/index.js @@ -117,10 +117,10 @@ const doProcessEndpoints = async work => { { username: endpoint.name } ); - const slugList = ` _${[...new Set(mergeFileNames)].join(", ")}_`; + const slugList = ` : _${[...new Set(mergeFileNames)].join(", ")}_`; await slackBot.Chat( - `${opCount} changes.${slugList.length < 300 ? slugList : ""}` + `${opCount} changes${slugList.length < 300 ? slugList : "."}` ); for (const commitReport of commitReports) {