diff options
Diffstat (limited to 'test/tools/vendor/github.com/vbatts/git-validation/rules')
4 files changed, 195 insertions, 0 deletions
diff --git a/test/tools/vendor/github.com/vbatts/git-validation/rules/danglingwhitespace/rule.go b/test/tools/vendor/github.com/vbatts/git-validation/rules/danglingwhitespace/rule.go new file mode 100644 index 000000000..dab3a984b --- /dev/null +++ b/test/tools/vendor/github.com/vbatts/git-validation/rules/danglingwhitespace/rule.go @@ -0,0 +1,39 @@ +package danglingwhitespace + +import ( + "github.com/vbatts/git-validation/git" + "github.com/vbatts/git-validation/validate" +) + +var ( + // DanglingWhitespace is the rule for checking the presence of dangling + // whitespaces on line endings. + DanglingWhitespace = validate.Rule{ + Name: "dangling-whitespace", + Description: "checking the presence of dangling whitespaces on line endings", + Run: ValidateDanglingWhitespace, + Default: true, + } +) + +func init() { + validate.RegisterRule(DanglingWhitespace) +} + +// ValidateDanglingWhitespace runs Git's check to look for whitespace errors. +func ValidateDanglingWhitespace(r validate.Rule, c git.CommitEntry) (vr validate.Result) { + vr.CommitEntry = c + vr.Msg = "commit does not have any whitespace errors" + vr.Pass = true + + _, err := git.Check(c["commit"]) + if err != nil { + vr.Pass = false + if err.Error() == "exit status 2" { + vr.Msg = "has whitespace errors. See `git show --check " + c["commit"] + "`." + } else { + vr.Msg = "errored with: " + err.Error() + } + } + return +} diff --git a/test/tools/vendor/github.com/vbatts/git-validation/rules/dco/dco.go b/test/tools/vendor/github.com/vbatts/git-validation/rules/dco/dco.go new file mode 100644 index 000000000..a42ea06ac --- /dev/null +++ b/test/tools/vendor/github.com/vbatts/git-validation/rules/dco/dco.go @@ -0,0 +1,51 @@ +package dco + +import ( + "regexp" + "strings" + + "github.com/vbatts/git-validation/git" + "github.com/vbatts/git-validation/validate" +) + +func init() { + validate.RegisterRule(DcoRule) +} + +var ( + // ValidDCO is the regexp for signed off DCO + ValidDCO = regexp.MustCompile(`^Signed-off-by: ([^<]+) <([^<>@]+@[^<>]+)>$`) + // DcoRule is the rule being registered + DcoRule = validate.Rule{ + Name: "DCO", + Description: "makes sure the commits are signed", + Run: ValidateDCO, + Default: true, + } +) + +// ValidateDCO checks that the commit has been signed off, per the DCO process +func ValidateDCO(r validate.Rule, c git.CommitEntry) (vr validate.Result) { + vr.CommitEntry = c + if len(strings.Split(c["parent"], " ")) > 1 { + vr.Pass = true + vr.Msg = "merge commits do not require DCO" + return vr + } + + hasValid := false + for _, line := range strings.Split(c["body"], "\n") { + if ValidDCO.MatchString(line) { + hasValid = true + } + } + if !hasValid { + vr.Pass = false + vr.Msg = "does not have a valid DCO" + } else { + vr.Pass = true + vr.Msg = "has a valid DCO" + } + + return vr +} diff --git a/test/tools/vendor/github.com/vbatts/git-validation/rules/messageregexp/rule.go b/test/tools/vendor/github.com/vbatts/git-validation/rules/messageregexp/rule.go new file mode 100644 index 000000000..98587f262 --- /dev/null +++ b/test/tools/vendor/github.com/vbatts/git-validation/rules/messageregexp/rule.go @@ -0,0 +1,61 @@ +package messageregexp + +import ( + "fmt" + "regexp" + "strings" + + "github.com/vbatts/git-validation/git" + "github.com/vbatts/git-validation/validate" +) + +func init() { + validate.RegisterRule(RegexpRule) +} + +var ( + // RegexpRule for validating a user provided regex on the commit messages + RegexpRule = validate.Rule{ + Name: "message_regexp", + Description: "checks the commit message for a user provided regular expression", + Run: ValidateMessageRegexp, + Default: false, // only for users specifically calling it through -run ... + } +) + +// ValidateMessageRegexp is the message regex func to run +func ValidateMessageRegexp(r validate.Rule, c git.CommitEntry) (vr validate.Result) { + if r.Value == "" { + vr.Pass = true + vr.Msg = "noop: message_regexp value is blank" + return vr + } + + re := regexp.MustCompile(r.Value) + vr.CommitEntry = c + if len(strings.Split(c["parent"], " ")) > 1 { + vr.Pass = true + vr.Msg = "merge commits are not checked for message_regexp" + return vr + } + + hasValid := false + for _, line := range strings.Split(c["subject"], "\n") { + if re.MatchString(line) { + hasValid = true + } + } + for _, line := range strings.Split(c["body"], "\n") { + if re.MatchString(line) { + hasValid = true + } + } + if !hasValid { + vr.Pass = false + vr.Msg = fmt.Sprintf("commit message does not match %q", r.Value) + } else { + vr.Pass = true + vr.Msg = fmt.Sprintf("commit message matches %q", r.Value) + } + return vr +} diff --git a/test/tools/vendor/github.com/vbatts/git-validation/rules/shortsubject/shortsubject.go b/test/tools/vendor/github.com/vbatts/git-validation/rules/shortsubject/shortsubject.go new file mode 100644 index 000000000..8fd033601 --- /dev/null +++ b/test/tools/vendor/github.com/vbatts/git-validation/rules/shortsubject/shortsubject.go @@ -0,0 +1,44 @@ +package shortsubject + +import ( + "strings" + + "github.com/vbatts/git-validation/git" + "github.com/vbatts/git-validation/validate" +) + +var ( + // ShortSubjectRule is the rule being registered + ShortSubjectRule = validate.Rule{ + Name: "short-subject", + Description: "commit subjects are strictly less than 90 (github ellipsis length)", + Run: ValidateShortSubject, + Default: true, + } +) + +func init() { + validate.RegisterRule(ShortSubjectRule) +} + +// ValidateShortSubject checks that the commit's subject is strictly less than +// 90 characters (preferably not more than 72 chars). +func ValidateShortSubject(r validate.Rule, c git.CommitEntry) (vr validate.Result) { + if len(strings.Split(c["parent"], " ")) > 1 { + vr.Pass = true + vr.Msg = "merge commits do not require length check" + return vr + } + if len(c["subject"]) >= 90 { + vr.Pass = false + vr.Msg = "commit subject exceeds 90 characters" + return + } + vr.Pass = true + if len(c["subject"]) > 72 { + vr.Msg = "commit subject is under 90 characters, but is still more than 72 chars" + } else { + vr.Msg = "commit subject is 72 characters or less! *yay*" + } + return +} |
