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