refactor(convention): replace commit parseHeader with updateType
parent
e4a5fa00cd
commit
daf3f0b36d
|
@ -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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,4 +11,5 @@ const (
|
||||||
RefactorType = "refactor"
|
RefactorType = "refactor"
|
||||||
PerfType = "perf"
|
PerfType = "perf"
|
||||||
TestType = "test"
|
TestType = "test"
|
||||||
|
MiscType = "misc"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue