1
0
Fork 0
mirror of https://github.com/vbatts/git-validation.git synced 2024-11-17 05:48:37 +00:00
git-validation/rules/shortsubject/rule.go
Vincent Batts d614ccf997 *: run tests in a runner
for cleanliness and ease of testing

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2015-10-06 10:44:04 -04:00

36 lines
960 B
Go

package shortsubject
import (
"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,
}
)
func init() {
validate.RegisterRule(ShortSubjectRule)
}
// ValidateShortSubject checks that the commit's subject is strictly less than
// 90 characters (preferrably not more than 72 chars).
func ValidateShortSubject(c git.CommitEntry) (vr validate.Result) {
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 not more than 90 characters, but is still more than 72 chars"
} else {
vr.Msg = "commit subject is 72 characters or less! *yay*"
}
return
}