refactor(convention): replace commit parseHeader with updateType

main
Tran Hau 2021-01-12 01:25:06 +07:00
parent e4a5fa00cd
commit daf3f0b36d
2 changed files with 11 additions and 16 deletions

View File

@ -28,32 +28,26 @@ func NewCommit(c git.Commit) (result Commit, err error) {
return return
} }
header := strings.TrimSpace(messages[0]) result.RawHeader = strings.TrimSpace(messages[0])
if err = parseHeader(header, &result); err != nil { result.UpdateType()
return
}
return return
} }
func (c Commit) GetType() string { func (c *Commit) GetType() string {
return c.Type return c.Type
} }
func (c Commit) String() string { func (c *Commit) String() string {
return c.RawHeader return c.RawHeader
} }
func parseHeader(header string, commit *Commit) error { func (c *Commit) UpdateType() {
if !headerRegex.MatchString(header) { if !headerRegex.MatchString(c.RawHeader) {
return errors.New("wrong header format") c.Type = MiscType
return
} }
commit.RawHeader = header headerSubmatches := headerRegex.FindStringSubmatch(c.RawHeader)
c.Type = strings.ToLower(headerSubmatches[1])
headerSubmatches := headerRegex.FindStringSubmatch(header)
commit.Type = strings.ToLower(headerSubmatches[1])
return nil
} }

View File

@ -11,4 +11,5 @@ const (
RefactorType = "refactor" RefactorType = "refactor"
PerfType = "perf" PerfType = "perf"
TestType = "test" TestType = "test"
MiscType = "misc"
) )