feat(convention): remove directly access conventional commit

main
hau 2021-01-05 17:56:11 +07:00 committed by Nguyen Tran Hau
parent 5701a6d5c4
commit 84c73e3eef
2 changed files with 13 additions and 7 deletions

View File

@ -70,14 +70,14 @@ func (g *MarkdownGenerator) getNewNodes(commits []convention.Commit) []markdown.
commitBases[othersType] = make([]markdown.Node, 0, defaultNodesLen) commitBases[othersType] = make([]markdown.Node, 0, defaultNodesLen)
for _, commit := range commits { for _, commit := range commits {
t := getType(commit.Type) t := getType(commit.GetType())
switch t { switch t {
case addedType: case addedType:
commitBases[addedType] = append(commitBases[addedType], markdown.NewListItem(commit.RawHeader)) commitBases[addedType] = append(commitBases[addedType], markdown.NewListItem(commit.String()))
case fixedType: case fixedType:
commitBases[fixedType] = append(commitBases[fixedType], markdown.NewListItem(commit.RawHeader)) commitBases[fixedType] = append(commitBases[fixedType], markdown.NewListItem(commit.String()))
case othersType: case othersType:
commitBases[othersType] = append(commitBases[othersType], markdown.NewListItem(commit.RawHeader)) commitBases[othersType] = append(commitBases[othersType], markdown.NewListItem(commit.String()))
default: default:
continue continue
} }

View File

@ -13,9 +13,7 @@ import (
// [optional body] // [optional body]
// [optional footer(s)] // [optional footer(s)]
var ( var headerRegex = regexp.MustCompile(`(?P<type>[a-zA-Z]+)(?P<scope>\([a-zA-Z]+\))?(?P<attention>!)?:\s(?P<description>.+)`)
headerRegex = regexp.MustCompile(`(?P<type>[a-zA-Z]+)(?P<scope>\([a-zA-Z]+\))?(?P<attention>!)?:\s(?P<description>.+)`)
)
type Commit struct { type Commit struct {
RawHeader string RawHeader string
@ -38,6 +36,14 @@ func NewCommit(c git.Commit) (result Commit, err error) {
return return
} }
func (c Commit) GetType() string {
return c.Type
}
func (c Commit) String() string {
return c.RawHeader
}
func parseHeader(header string, commit *Commit) error { func parseHeader(header string, commit *Commit) error {
if !headerRegex.MatchString(header) { if !headerRegex.MatchString(header) {
return errors.New("wrong header format") return errors.New("wrong header format")