podman

Форк
0
102 строки · 3.1 Кб
1
package main
2

3
import (
4
	"flag"
5
	"fmt"
6
	"os"
7
	"strings"
8

9
	"github.com/sirupsen/logrus"
10
	_ "github.com/vbatts/git-validation/rules/danglingwhitespace"
11
	_ "github.com/vbatts/git-validation/rules/dco"
12
	_ "github.com/vbatts/git-validation/rules/messageregexp"
13
	_ "github.com/vbatts/git-validation/rules/shortsubject"
14
	"github.com/vbatts/git-validation/validate"
15
)
16

17
var (
18
	flCommitRange  = flag.String("range", "", "use this commit range instead (implies -no-travis)")
19
	flListRules    = flag.Bool("list-rules", false, "list the rules registered")
20
	flRun          = flag.String("run", "", "comma delimited list of rules to run. Defaults to all.")
21
	flVerbose      = flag.Bool("v", false, "verbose")
22
	flDebug        = flag.Bool("D", false, "debug output")
23
	flQuiet        = flag.Bool("q", false, "less output")
24
	flDir          = flag.String("d", ".", "git directory to validate from")
25
	flNoGithub     = flag.Bool("no-github", false, "disables Github Actions environment checks (when env GITHUB_ACTIONS=true is set)")
26
	flNoTravis     = flag.Bool("no-travis", false, "disables travis environment checks (when env TRAVIS=true is set)")
27
	flTravisPROnly = flag.Bool("travis-pr-only", true, "when on travis, only run validations if the CI-Build is checking pull-request build")
28
)
29

30
func init() {
31
	logrus.SetOutput(os.Stderr)
32
}
33

34
func main() {
35
	flag.Parse()
36

37
	if *flDebug {
38
		os.Setenv("DEBUG", "1")
39
	}
40
	if *flQuiet {
41
		os.Setenv("QUIET", "1")
42
	}
43

44
	if *flListRules {
45
		for _, r := range validate.RegisteredRules {
46
			fmt.Printf("%q -- %s\n", r.Name, r.Description)
47
		}
48
		return
49
	}
50

51
	if *flTravisPROnly && strings.ToLower(os.Getenv("TRAVIS_PULL_REQUEST")) == "false" {
52
		fmt.Printf("only to check travis PR builds and this not a PR build. yielding.\n")
53
		return
54
	}
55

56
	// rules to be used
57
	var rules []validate.Rule
58
	for _, r := range validate.RegisteredRules {
59
		// only those that are Default
60
		if r.Default {
61
			rules = append(rules, r)
62
		}
63
	}
64
	// or reduce the set being run to what the user provided
65
	if *flRun != "" {
66
		rules = validate.FilterRules(validate.RegisteredRules, validate.SanitizeFilters(*flRun))
67
	}
68
	if os.Getenv("DEBUG") != "" {
69
		logrus.Printf("%#v", rules) // XXX maybe reduce this list
70
	}
71

72
	var commitRange = *flCommitRange
73
	if commitRange == "" {
74
		if strings.ToLower(os.Getenv("TRAVIS")) == "true" && !*flNoTravis {
75
			if os.Getenv("TRAVIS_COMMIT_RANGE") != "" {
76
				commitRange = strings.Replace(os.Getenv("TRAVIS_COMMIT_RANGE"), "...", "..", 1)
77
			} else if os.Getenv("TRAVIS_COMMIT") != "" {
78
				commitRange = os.Getenv("TRAVIS_COMMIT")
79
			}
80
		}
81
		// https://docs.github.com/en/actions/reference/environment-variables
82
		if strings.ToLower(os.Getenv("GITHUB_ACTIONS")) == "true" && !*flNoGithub {
83
			commitRange = fmt.Sprintf("%s..%s", os.Getenv("GITHUB_SHA"), "HEAD")
84
		}
85
	}
86

87
	logrus.Infof("using commit range: %s", commitRange)
88
	runner, err := validate.NewRunner(*flDir, rules, commitRange, *flVerbose)
89
	if err != nil {
90
		logrus.Fatal(err)
91
	}
92

93
	if err := runner.Run(); err != nil {
94
		logrus.Fatal(err)
95
	}
96
	_, fail := runner.Results.PassFail()
97
	if fail > 0 {
98
		fmt.Printf("%d commits to fix\n", fail)
99
		os.Exit(1)
100
	}
101

102
}
103

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.