2015-10-05 23:02:31 +00:00
|
|
|
package shortsubject
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vbatts/git-validation/git"
|
|
|
|
"github.com/vbatts/git-validation/validate"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-10-06 14:44:04 +00:00
|
|
|
// ShortSubjectRule is the rule being registered
|
2015-10-05 23:02:31 +00:00
|
|
|
ShortSubjectRule = validate.Rule{
|
|
|
|
Name: "short-subject",
|
|
|
|
Description: "commit subjects are strictly less than 90 (github ellipsis length)",
|
|
|
|
Run: ValidateShortSubject,
|
2017-10-09 19:49:59 +00:00
|
|
|
Default: true,
|
2015-10-05 23:02:31 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
validate.RegisterRule(ShortSubjectRule)
|
|
|
|
}
|
|
|
|
|
2015-10-06 14:44:04 +00:00
|
|
|
// ValidateShortSubject checks that the commit's subject is strictly less than
|
2016-04-05 14:06:48 +00:00
|
|
|
// 90 characters (preferably not more than 72 chars).
|
2017-10-09 19:49:59 +00:00
|
|
|
func ValidateShortSubject(r validate.Rule, c git.CommitEntry) (vr validate.Result) {
|
2015-10-05 23:02:31 +00:00
|
|
|
if len(c["subject"]) >= 90 {
|
|
|
|
vr.Pass = false
|
|
|
|
vr.Msg = "commit subject exceeds 90 characters"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
vr.Pass = true
|
2015-10-06 14:44:04 +00:00
|
|
|
if len(c["subject"]) > 72 {
|
2016-04-05 14:06:48 +00:00
|
|
|
vr.Msg = "commit subject is under 90 characters, but is still more than 72 chars"
|
2015-10-06 14:44:04 +00:00
|
|
|
} else {
|
|
|
|
vr.Msg = "commit subject is 72 characters or less! *yay*"
|
|
|
|
}
|
2015-10-05 23:02:31 +00:00
|
|
|
return
|
|
|
|
}
|