feat: skip empty commit
parent
146497ac8b
commit
bbd8bf46fc
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue