aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/vbatts/git-validation/validate/runner.go
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-05-03 18:34:38 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-05-03 18:43:18 +0200
commit9166894c696582ee37893ce92a694ba227744fa0 (patch)
tree8b4c9ffa20de8a4a484c0a427fc74b5c22634994 /vendor/github.com/vbatts/git-validation/validate/runner.go
parent1e0c50df38ff955011f7ebb83a0268f3f1cd2841 (diff)
downloadpodman-9166894c696582ee37893ce92a694ba227744fa0.tar.gz
podman-9166894c696582ee37893ce92a694ba227744fa0.tar.bz2
podman-9166894c696582ee37893ce92a694ba227744fa0.zip
vendor test dependencies instead of installing via network
We can vendor the test dependencies such as go-md2man, git-validation and goimports. This allows us to always install the same version as specified in go.mod. Also we do not rely on a network connection for this. The advantage with this method is that dependabot will also update the dependencies for us and we do not have to hardcode versions in the Makefile. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'vendor/github.com/vbatts/git-validation/validate/runner.go')
-rw-r--r--vendor/github.com/vbatts/git-validation/validate/runner.go109
1 files changed, 109 insertions, 0 deletions
diff --git a/vendor/github.com/vbatts/git-validation/validate/runner.go b/vendor/github.com/vbatts/git-validation/validate/runner.go
new file mode 100644
index 000000000..eea61fba1
--- /dev/null
+++ b/vendor/github.com/vbatts/git-validation/validate/runner.go
@@ -0,0 +1,109 @@
+package validate
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/vbatts/git-validation/git"
+)
+
+// Runner is the for processing a set of rules against a range of commits
+type Runner struct {
+ Root string
+ Rules []Rule
+ Results Results
+ Verbose bool
+ CommitRange string // if this is empty, then it will default to FETCH_HEAD, then HEAD
+}
+
+// NewRunner returns an initiallized Runner.
+func NewRunner(root string, rules []Rule, commitrange string, verbose bool) (*Runner, error) {
+ newroot, err := filepath.Abs(root)
+ if err != nil {
+ return nil, fmt.Errorf("failed to get absolute path of %q: %s", root, err)
+ }
+ if commitrange == "" {
+ var err error
+ cwd, err := os.Getwd()
+ if err != nil {
+ return nil, err
+ }
+ defer os.Chdir(cwd)
+
+ if err := os.Chdir(newroot); err != nil {
+ return nil, err
+ }
+ commitrange, err = git.FetchHeadCommit()
+ if err != nil {
+ commitrange, err = git.HeadCommit()
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+ return &Runner{
+ Root: newroot,
+ Rules: rules,
+ CommitRange: commitrange,
+ Verbose: verbose,
+ }, nil
+}
+
+// Run processes the rules for each commit in the range provided
+func (r *Runner) Run() error {
+ cwd, err := os.Getwd()
+ if err != nil {
+ return err
+ }
+ defer os.Chdir(cwd)
+
+ if err := os.Chdir(r.Root); err != nil {
+ return err
+ }
+
+ // collect the entries
+ c, err := git.Commits(r.CommitRange)
+ if err != nil {
+ return err
+ }
+
+ // run them and show results
+ for _, commit := range c {
+ if os.Getenv("QUIET") == "" {
+ fmt.Printf(" * %s %q ... ", commit["abbreviated_commit"], commit["subject"])
+ }
+ vr := Commit(commit, r.Rules)
+ r.Results = append(r.Results, vr...)
+ _, fail := vr.PassFail()
+ if os.Getenv("QUIET") != "" {
+ if fail != 0 {
+ for _, res := range vr {
+ if !res.Pass {
+ fmt.Printf(" %s - FAIL - %s\n", commit["abbreviated_commit"], res.Msg)
+ }
+ }
+ }
+ // everything else in the loop is printing output.
+ // If we're quiet, then just continue
+ continue
+ }
+ if fail == 0 {
+ fmt.Println("PASS")
+ } else {
+ fmt.Println("FAIL")
+ }
+ for _, res := range vr {
+ if r.Verbose {
+ if res.Pass {
+ fmt.Printf(" - PASS - %s\n", res.Msg)
+ } else {
+ fmt.Printf(" - FAIL - %s\n", res.Msg)
+ }
+ } else if !res.Pass {
+ fmt.Printf(" - FAIL - %s\n", res.Msg)
+ }
+ }
+ }
+ return nil
+}