feat: skip empty commit

main
sudo pacman -Syu 2021-05-11 11:43:26 +07:00
parent 146497ac8b
commit bbd8bf46fc
1 changed files with 6 additions and 9 deletions

View File

@ -1,7 +1,6 @@
package convention
import (
"errors"
"fmt"
"regexp"
"strings"
@ -10,21 +9,19 @@ import (
"github.com/haunt98/clock"
)
var (
ErrEmptyCommit = errors.New("empty commit")
headerRegex = regexp.MustCompile(`(?P<type>[a-zA-Z]+)(?P<scope>\([a-zA-Z]+\))?(?P<attention>!)?:\s(?P<description>.+)`)
)
var headerRegex = regexp.MustCompile(`(?P<type>[a-zA-Z]+)(?P<scope>\([a-zA-Z]+\))?(?P<attention>!)?:\s(?P<description>.+)`)
type OptionFn func(*Commit) error
func GetRawHeader(gitCommit git.Commit) OptionFn {
return func(c *Commit) error {
// Skip empty commit
if gitCommit.Message == "" {
return nil
}
message := strings.TrimSpace(gitCommit.Message)
messages := strings.Split(message, "\n")
if len(messages) == 0 {
return ErrEmptyCommit
}
c.RawHeader = messages[0]