1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2024-11-25 17:45:40 +00:00
git-validation/rules/shortsubject/shortsubject.go
Vincent Batts cb8f88ffbf
shortsubject: merge commits may be long
due to automated "merge of <hash> in to <hash>"

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-11-15 11:59:18 -05:00

44 lines
1.1 KiB
Go

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
}