From 08949b52ede140558c36138ef56e7c2621b27255 Mon Sep 17 00:00:00 2001 From: Andrea Brancaleoni Date: Thu, 24 Oct 2024 12:19:39 -0700 Subject: [PATCH] sendSlackMessage: don't send again if the there it increased by one finding every time use filteredMessage as a way to prevent over notification on slack. This would not send again any notification if there is an extra finding on a given PR, for the previous 50 message, or a day ago. This would debounce chaingun messages in any slack channel from the main action itself. It should not have any other side-effect. This will effectively change the hash function, so invalidate the debounce for all the previous messages. --- src/sendSlackMessage.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sendSlackMessage.js b/src/sendSlackMessage.js index 20eea5be..22c354c9 100644 --- a/src/sendSlackMessage.js +++ b/src/sendSlackMessage.js @@ -50,6 +50,8 @@ export default async function sendSlackMessage ({ throw new Error('message || token is required!') } + const filteredMessage = message?.replace(/Findings: \n+/g, 'Findings: n+') + if (colorCodes[color]) { color = colorCodes[color] } @@ -68,7 +70,7 @@ export default async function sendSlackMessage ({ const crypto = await import('crypto') const hash = crypto.createHash('sha256') if (text !== null) hash.update(text) - if (message !== null) hash.update(message) + if (filteredMessage !== null) hash.update(filteredMessage) if (color !== null) hash.update(color) const hashHex = hash.digest('hex')