refactor(allowlist): deduplicate commits & keywords (#1596)

This commit is contained in:
Richard Gomez authored and GitHub committed 2024-10-24 07:28:55 -05:00
1 parent 50c2818167
commit 8cf93b9ad5
3 files changed
+81 -1

No files matched your search

+19
View File
@@ -4,6 +4,8 @@ import (
"fmt"
"regexp"
"strings"
"golang.org/x/exp/maps"
)
type AllowlistMatchCondition int
@@ -95,5 +97,22 @@ func (a *Allowlist) Validate() error {
return fmt.Errorf("[[rules.allowlists]] must contain at least one check for: commits, paths, regexes, or stopwords")
}
// Deduplicate commits and stopwords.
if len(a.Commits) > 0 {
uniqueCommits := make(map[string]struct{})
for _, commit := range a.Commits {
uniqueCommits[commit] = struct{}{}
}
a.Commits = maps.Keys(uniqueCommits)
}
if len(a.StopWords) > 0 {
uniqueStopwords := make(map[string]struct{})
for _, stopWord := range a.StopWords {
uniqueStopwords[stopWord] = struct{}{}
}
a.StopWords = maps.Keys(uniqueStopwords)
}
return nil
}