Prepare for next release #8
1 changed files with 2 additions and 9 deletions
|
@ -13,33 +13,26 @@ func ValidateConventionalCommit(commit string) error {
|
||||||
// type!: description
|
// type!: description
|
||||||
// or
|
// or
|
||||||
// type: description
|
// type: description
|
||||||
re := regexp.MustCompile(`^(?P<type>[a-z]+)(?P<scope>\([a-z]+\))?(?P<breaking>!)?: (?P<description>[a-z].+)$`)
|
re := regexp.MustCompile(`^(?P<type>[a-z]+)(?P<scope>\([a-z]+\))?(?P<breaking>!)?: (?P<description>.+)$`)
|
||||||
match := re.FindStringSubmatch(commit)
|
match := re.FindStringSubmatch(commit)
|
||||||
|
|
||||||
if len(match) == 0 {
|
if len(match) == 0 {
|
||||||
return fmt.Errorf("Invalid PR title")
|
return fmt.Errorf("invalid commit format")
|
||||||
}
|
}
|
||||||
|
|
||||||
typeIndex := re.SubexpIndex("type")
|
typeIndex := re.SubexpIndex("type")
|
||||||
scopeIndex := re.SubexpIndex("scope")
|
scopeIndex := re.SubexpIndex("scope")
|
||||||
breakingIndex := re.SubexpIndex("breaking")
|
breakingIndex := re.SubexpIndex("breaking")
|
||||||
descriptionIndex := re.SubexpIndex("description")
|
|
||||||
|
|
||||||
commitType := match[typeIndex]
|
commitType := match[typeIndex]
|
||||||
scope := match[scopeIndex]
|
scope := match[scopeIndex]
|
||||||
breaking := match[breakingIndex]
|
breaking := match[breakingIndex]
|
||||||
description := match[descriptionIndex]
|
|
||||||
|
|
||||||
// Type MUST be lowercase
|
// Type MUST be lowercase
|
||||||
if commitType != strings.ToLower(commitType) {
|
if commitType != strings.ToLower(commitType) {
|
||||||
return fmt.Errorf("type must be lowercase")
|
return fmt.Errorf("type must be lowercase")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Description MUST start with lowercase
|
|
||||||
if description != strings.ToLower(description) {
|
|
||||||
return fmt.Errorf("description must start with lowercase")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scope MUST be lowercase
|
// Scope MUST be lowercase
|
||||||
if scope != "" && scope != strings.ToLower(scope) {
|
if scope != "" && scope != strings.ToLower(scope) {
|
||||||
return fmt.Errorf("scope must be lowercase")
|
return fmt.Errorf("scope must be lowercase")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue