mirror of
https://github.com/vbatts/git-validation.git
synced 2025-07-02 07:08:29 +00:00
*: run tests in a runner
for cleanliness and ease of testing Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
b9413c60c8
commit
d614ccf997
4 changed files with 119 additions and 52 deletions
52
main.go
52
main.go
|
@ -6,7 +6,6 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/vbatts/git-validation/git"
|
||||
_ "github.com/vbatts/git-validation/rules/dco"
|
||||
_ "github.com/vbatts/git-validation/rules/shortsubject"
|
||||
"github.com/vbatts/git-validation/validate"
|
||||
|
@ -17,13 +16,15 @@ var (
|
|||
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")
|
||||
flDir = flag.String("d", ".", "git directory to validate from")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *flVerbose {
|
||||
git.Verbose = true
|
||||
if *flDebug {
|
||||
os.Setenv("DEBUG", "1")
|
||||
}
|
||||
|
||||
if *flListRules {
|
||||
|
@ -39,53 +40,18 @@ func main() {
|
|||
rules = validate.FilterRules(rules, validate.SanitizeFilters(*flRun))
|
||||
}
|
||||
|
||||
// Guess the commits we're working with
|
||||
var commitrange string
|
||||
if *flCommitRange != "" {
|
||||
commitrange = *flCommitRange
|
||||
} else {
|
||||
var err error
|
||||
commitrange, err = git.FetchHeadCommit()
|
||||
if err != nil {
|
||||
commitrange, err = git.HeadCommit()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// collect the entries
|
||||
c, err := git.Commits(commitrange)
|
||||
runner, err := validate.NewRunner(*flDir, rules, *flCommitRange, *flVerbose)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// run them and show results
|
||||
results := validate.Results{}
|
||||
for _, commit := range c {
|
||||
fmt.Printf(" * %s %s ... ", commit["abbreviated_commit"], commit["subject"])
|
||||
vr := validate.Commit(commit, rules)
|
||||
results = append(results, vr...)
|
||||
if _, fail := vr.PassFail(); fail == 0 {
|
||||
fmt.Println("PASS")
|
||||
} else {
|
||||
fmt.Println("FAIL")
|
||||
}
|
||||
for _, r := range vr {
|
||||
if *flVerbose {
|
||||
if r.Pass {
|
||||
fmt.Printf("ok %s\n", r.Msg)
|
||||
} else {
|
||||
fmt.Printf("not ok %s\n", r.Msg)
|
||||
}
|
||||
} else if !r.Pass {
|
||||
fmt.Printf("not ok %s\n", r.Msg)
|
||||
}
|
||||
}
|
||||
if err := runner.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, fail := results.PassFail()
|
||||
_, fail := runner.Results.PassFail()
|
||||
if fail > 0 {
|
||||
fmt.Printf("%d issues to fix\n", fail)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue