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,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
validate.RegisterRule(ShortSubjectRule)
|
|
|
|
}
|
|
|
|
|
2015-10-06 14:44:04 +00:00
|
|
|
// ValidateShortSubject checks that the commit's subject is strictly less than
|
|
|
|
// 90 characters (preferrably not more than 72 chars).
|
2015-10-05 23:02:31 +00:00
|
|
|
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
|
2015-10-06 14:44:04 +00:00
|
|
|
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*"
|
|
|
|
}
|
2015-10-05 23:02:31 +00:00
|
|
|
return
|
|
|
|
}
|