1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2024-12-28 00:16:29 +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

@ -28,6 +28,11 @@ func main() {
return
}
rules := validate.RegisteredRules
if *flRun != "" {
rules = validate.FilterRules(rules, validate.SanitizeFilters(*flRun))
}
var commitrange string
if *flCommitRange != "" {
commitrange = *flCommitRange
@ -47,7 +52,7 @@ func main() {
results := validate.Results{}
for _, commit := range c {
fmt.Printf(" * %s %s ... ", commit["abbreviated_commit"], commit["subject"])
vr := validate.Commit(commit, validate.RegisteredRules)
vr := validate.Commit(commit, rules)
results = append(results, vr...)
if _, fail := vr.PassFail(); fail == 0 {
fmt.Println("PASS")

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
}