1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2025-07-23 07:40:28 +00:00

main: add filtering of rules to run

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2015-10-05 18:29:24 -04:00
parent c10ba9c097
commit 03bda4bcb2
2 changed files with 37 additions and 2 deletions

View file

@ -1,6 +1,10 @@
package validate
import "github.com/vbatts/git-validation/git"
import (
"strings"
"github.com/vbatts/git-validation/git"
)
var (
// RegisteredRules are the standard validation to perform on git commits
@ -49,3 +53,29 @@ func (vr Results) PassFail() (pass int, fail int) {
}
return pass, fail
}
// SanitizeFilters takes a comma delimited list and returns the cleaned items in the list
func SanitizeFilters(filt string) (excludes []string) {
for _, item := range strings.Split(filt, ",") {
excludes = append(excludes, strings.TrimSpace(item))
}
return
}
// FilterRules takes a set of rules and a list of short names to exclude, and returns the reduced set.
// The comparison is case insensitive.
func FilterRules(rules []Rule, excludes []string) []Rule {
ret := []Rule{}
for _, r := range rules {
for _, e := range excludes {
if strings.ToLower(r.Name) == strings.ToLower(e) {
ret = append(ret, r)
}
}
}
return ret
}