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:
parent
c10ba9c097
commit
03bda4bcb2
2 changed files with 37 additions and 2 deletions
7
main.go
7
main.go
|
@ -28,6 +28,11 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rules := validate.RegisteredRules
|
||||||
|
if *flRun != "" {
|
||||||
|
rules = validate.FilterRules(rules, validate.SanitizeFilters(*flRun))
|
||||||
|
}
|
||||||
|
|
||||||
var commitrange string
|
var commitrange string
|
||||||
if *flCommitRange != "" {
|
if *flCommitRange != "" {
|
||||||
commitrange = *flCommitRange
|
commitrange = *flCommitRange
|
||||||
|
@ -47,7 +52,7 @@ func main() {
|
||||||
results := validate.Results{}
|
results := validate.Results{}
|
||||||
for _, commit := range c {
|
for _, commit := range c {
|
||||||
fmt.Printf(" * %s %s ... ", commit["abbreviated_commit"], commit["subject"])
|
fmt.Printf(" * %s %s ... ", commit["abbreviated_commit"], commit["subject"])
|
||||||
vr := validate.Commit(commit, validate.RegisteredRules)
|
vr := validate.Commit(commit, rules)
|
||||||
results = append(results, vr...)
|
results = append(results, vr...)
|
||||||
if _, fail := vr.PassFail(); fail == 0 {
|
if _, fail := vr.PassFail(); fail == 0 {
|
||||||
fmt.Println("PASS")
|
fmt.Println("PASS")
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package validate
|
package validate
|
||||||
|
|
||||||
import "github.com/vbatts/git-validation/git"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/vbatts/git-validation/git"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// RegisteredRules are the standard validation to perform on git commits
|
// 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
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue