Skip to content

Commit

Permalink
sendSlackMessage: don't send again if the there it increased by one f…
Browse files Browse the repository at this point in the history
…inding 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.
  • Loading branch information
thypon committed Oct 24, 2024
1 parent b635c7f commit efce120
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sendSlackMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default async function sendSlackMessage ({
throw new Error('message || token is required!')
}

const filteredMessage = message?.replace(/Findings: \d+/g, 'Findings: n+')

if (colorCodes[color]) {
color = colorCodes[color]
}
Expand All @@ -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')

Expand Down

0 comments on commit efce120

Please sign in to comment.