aboutsummaryrefslogtreecommitdiff
path: root/test/tools/vendor/github.com/vbatts/git-validation/rules/messageregexp
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-05-05 05:53:18 -0400
committerGitHub <noreply@github.com>2022-05-05 05:53:18 -0400
commit88f8d398b357c60f8b78b8dedf1e1515a534b873 (patch)
tree6e3fa55f6c32b95c883480844193443b97540531 /test/tools/vendor/github.com/vbatts/git-validation/rules/messageregexp
parent7af4612d6b969329a78b4945c35a641449989a2d (diff)
parent3866143675a2ccf15095b75b2c97b858d8ef0ab5 (diff)
downloadpodman-88f8d398b357c60f8b78b8dedf1e1515a534b873.tar.gz
podman-88f8d398b357c60f8b78b8dedf1e1515a534b873.tar.bz2
podman-88f8d398b357c60f8b78b8dedf1e1515a534b873.zip
Merge pull request #14098 from Luap99/test-tools
vendor test dependencies instead of installing via network
Diffstat (limited to 'test/tools/vendor/github.com/vbatts/git-validation/rules/messageregexp')
-rw-r--r--test/tools/vendor/github.com/vbatts/git-validation/rules/messageregexp/rule.go61
1 files changed, 61 insertions, 0 deletions
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
+}