1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2025-04-22 23:04:42 +00:00
git-validation/rules/dco/dco.go
Akihiro Suda 9e62150976
dco: improve error message
The former message was unclear to a new contributor who does not know DCO

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-04-12 23:15:07 +09:00

51 lines
1.2 KiB
Go

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 Developer Certificate of Origin (DCO, https://developercertificate.org); run `git commit --amend --signoff` to sign DCO"
} else {
vr.Pass = true
vr.Msg = "has a valid DCO"
}
return vr
}