Add regex filter support
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful

This makes any filter that starts and ends in forward slashes act as a
regex filter instead of a simple substring filter.

Currently doesn't support trailing flags unlike actual JS regexes, so
modifiers should be used instead for that functionality:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier
This commit is contained in:
Norm 2024-12-17 23:42:35 -05:00
parent 4a50b1273d
commit 105154a42b

View file

@ -4,6 +4,10 @@ export const muteWordHits = (status, muteWords) => {
const statusText = status.text.toLowerCase()
const statusSummary = status.summary.toLowerCase()
const hits = filter(muteWords, (muteWord) => {
if (muteWord.startsWith('/') && muteWord.endsWith('/')) {
const muteRegex = new RegExp(muteWord.slice(1, -1))
return muteRegex.test(statusText) || muteRegex.test(statusSummary)
}
return statusText.includes(muteWord.toLowerCase()) || statusSummary.includes(muteWord.toLowerCase())
})