mirror of
https://github.com/vbatts/git-validation.git
synced 2025-05-29 16:22:26 +00:00
Initial commit
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
commit
c10ba9c097
7 changed files with 307 additions and 0 deletions
47
rules/dco/dco.go
Normal file
47
rules/dco/dco.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package dco
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/vbatts/git-validation/git"
|
||||
"github.com/vbatts/git-validation/validate"
|
||||
)
|
||||
|
||||
func init() {
|
||||
validate.RegisterRule(DcoRule)
|
||||
}
|
||||
|
||||
var (
|
||||
ValidDCO = regexp.MustCompile(`^Signed-off-by: ([^<]+) <([^<>@]+@[^<>]+)>$`)
|
||||
DcoRule = validate.Rule{
|
||||
Name: "DCO",
|
||||
Description: "makes sure the commits are signed",
|
||||
Run: ValidateDCO,
|
||||
}
|
||||
)
|
||||
|
||||
func ValidateDCO(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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue