2015-10-05 20:16:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
2016-04-05 17:16:40 +00:00
|
|
|
"strings"
|
2015-10-05 20:16:52 +00:00
|
|
|
|
|
|
|
_ "github.com/vbatts/git-validation/rules/dco"
|
2015-10-05 23:02:31 +00:00
|
|
|
_ "github.com/vbatts/git-validation/rules/shortsubject"
|
2015-10-05 20:16:52 +00:00
|
|
|
"github.com/vbatts/git-validation/validate"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
flCommitRange = flag.String("range", "", "use this commit range instead")
|
|
|
|
flListRules = flag.Bool("list-rules", false, "list the rules registered")
|
|
|
|
flRun = flag.String("run", "", "comma delimited list of rules to run. Defaults to all.")
|
|
|
|
flVerbose = flag.Bool("v", false, "verbose")
|
2015-10-06 14:44:04 +00:00
|
|
|
flDebug = flag.Bool("D", false, "debug output")
|
2016-01-14 15:29:35 +00:00
|
|
|
flQuiet = flag.Bool("q", false, "less output")
|
2015-10-06 14:44:04 +00:00
|
|
|
flDir = flag.String("d", ".", "git directory to validate from")
|
2016-04-05 17:16:40 +00:00
|
|
|
flNoTravis = flag.Bool("no-travis", false, "disables travis environment checks (when env TRAVIS=true is set)")
|
2015-10-05 20:16:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2015-10-06 14:44:04 +00:00
|
|
|
if *flDebug {
|
|
|
|
os.Setenv("DEBUG", "1")
|
2015-10-05 22:45:33 +00:00
|
|
|
}
|
2016-01-14 15:29:35 +00:00
|
|
|
if *flQuiet {
|
|
|
|
os.Setenv("QUIET", "1")
|
|
|
|
}
|
2015-10-05 22:45:33 +00:00
|
|
|
|
2015-10-05 20:16:52 +00:00
|
|
|
if *flListRules {
|
|
|
|
for _, r := range validate.RegisteredRules {
|
|
|
|
fmt.Printf("%q -- %s\n", r.Name, r.Description)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-10-05 22:55:05 +00:00
|
|
|
// reduce the set being run
|
2015-10-05 22:29:24 +00:00
|
|
|
rules := validate.RegisteredRules
|
|
|
|
if *flRun != "" {
|
|
|
|
rules = validate.FilterRules(rules, validate.SanitizeFilters(*flRun))
|
|
|
|
}
|
|
|
|
|
2016-04-05 17:16:40 +00:00
|
|
|
var commitRange = *flCommitRange
|
|
|
|
if strings.ToLower(os.Getenv("TRAVIS")) == "true" && !*flNoTravis {
|
|
|
|
if os.Getenv("TRAVIS_COMMIT_RANGE") != "" {
|
|
|
|
commitRange = os.Getenv("TRAVIS_COMMIT_RANGE")
|
|
|
|
} else if os.Getenv("TRAVIS_COMMIT") != "" {
|
|
|
|
commitRange = os.Getenv("TRAVIS_COMMIT")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runner, err := validate.NewRunner(*flDir, rules, commitRange, *flVerbose)
|
2015-10-05 20:16:52 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-10-06 14:44:04 +00:00
|
|
|
if err := runner.Run(); err != nil {
|
|
|
|
log.Fatal(err)
|
2015-10-05 20:16:52 +00:00
|
|
|
}
|
2015-10-06 14:44:04 +00:00
|
|
|
_, fail := runner.Results.PassFail()
|
2015-10-05 20:16:52 +00:00
|
|
|
if fail > 0 {
|
|
|
|
fmt.Printf("%d issues to fix\n", fail)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2015-10-06 14:44:04 +00:00
|
|
|
|
2015-10-05 20:16:52 +00:00
|
|
|
}
|