allowlist.go 577 B

123456789101112131415161718192021222324252627282930313233343536
  1. package config
  2. import "regexp"
  3. type Allowlist struct {
  4. Description string
  5. Regexes []*regexp.Regexp
  6. Paths []*regexp.Regexp
  7. Commits []string
  8. }
  9. func (a *Allowlist) CommitAllowed(c string) bool {
  10. if c == "" {
  11. return false
  12. }
  13. for _, commit := range a.Commits {
  14. if commit == c {
  15. return true
  16. }
  17. }
  18. return false
  19. }
  20. func (a *Allowlist) PathAllowed(path string) bool {
  21. if anyRegexMatch(path, a.Paths) {
  22. return true
  23. }
  24. return false
  25. }
  26. func (a *Allowlist) RegexAllowed(s string) bool {
  27. if anyRegexMatch(s, a.Regexes) {
  28. return true
  29. }
  30. return false
  31. }