mirror of
https://github.com/vbatts/git-validation.git
synced 2024-12-28 16:26:31 +00:00
f94dce37d6
It's (string, old, new, n), not (old, new, string, n) [1]. Fixes a
typo I'd introduced in cdd7165
(main: Return to using
TRAVIS_COMMIT_RANGE (with ... -> .. fix), 2017-03-21, #17).
[1]: https://golang.org/pkg/strings/#Replace
Signed-off-by: W. Trevor King <wking@tremily.us>
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
|
|
_ "github.com/vbatts/git-validation/rules/danglingwhitespace"
|
|
_ "github.com/vbatts/git-validation/rules/dco"
|
|
_ "github.com/vbatts/git-validation/rules/shortsubject"
|
|
"github.com/vbatts/git-validation/validate"
|
|
)
|
|
|
|
var (
|
|
flCommitRange = flag.String("range", "", "use this commit range instead (implies -no-travis)")
|
|
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")
|
|
flDebug = flag.Bool("D", false, "debug output")
|
|
flQuiet = flag.Bool("q", false, "less output")
|
|
flDir = flag.String("d", ".", "git directory to validate from")
|
|
flNoTravis = flag.Bool("no-travis", false, "disables travis environment checks (when env TRAVIS=true is set)")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
if *flDebug {
|
|
os.Setenv("DEBUG", "1")
|
|
}
|
|
if *flQuiet {
|
|
os.Setenv("QUIET", "1")
|
|
}
|
|
|
|
if *flListRules {
|
|
for _, r := range validate.RegisteredRules {
|
|
fmt.Printf("%q -- %s\n", r.Name, r.Description)
|
|
}
|
|
return
|
|
}
|
|
|
|
// reduce the set being run
|
|
rules := validate.RegisteredRules
|
|
if *flRun != "" {
|
|
rules = validate.FilterRules(rules, validate.SanitizeFilters(*flRun))
|
|
}
|
|
|
|
var commitRange = *flCommitRange
|
|
if commitRange == "" {
|
|
if strings.ToLower(os.Getenv("TRAVIS")) == "true" && !*flNoTravis {
|
|
if os.Getenv("TRAVIS_COMMIT_RANGE") != "" {
|
|
commitRange = strings.Replace(os.Getenv("TRAVIS_COMMIT_RANGE"), "...", "..", 1)
|
|
} else if os.Getenv("TRAVIS_COMMIT") != "" {
|
|
commitRange = os.Getenv("TRAVIS_COMMIT")
|
|
}
|
|
}
|
|
}
|
|
|
|
runner, err := validate.NewRunner(*flDir, rules, commitRange, *flVerbose)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if err := runner.Run(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
_, fail := runner.Results.PassFail()
|
|
if fail > 0 {
|
|
fmt.Printf("%d commits to fix\n", fail)
|
|
os.Exit(1)
|
|
}
|
|
|
|
}
|