@@ -18,28 +18,28 @@ const (
1818 footRegExStr = `^(?:(BREAKING[- ]CHANGE|(?:[A-Za-z-])+): |((?:[A-Za-z-])+) #)(.+)$`
1919)
2020
21- var defParser = newParser ()
22-
23- // Parse attempts to parse a commit message to a conventional commit
24- func Parse (message string ) (* Commit , error ) {
25- return defParser .parse (message )
26- }
27-
28- type parser struct {
21+ // Parser represent a conventional commit message parser
22+ type Parser struct {
2923 headerRegex , footerRegex * regexp.Regexp
3024}
3125
32- func newParser () * parser {
26+ // New returns a new parser
27+ func New () * Parser {
3328 headerRegex := regexp .MustCompile (headRegExStr )
3429 footerRegex := regexp .MustCompile (footRegExStr )
3530
36- return & parser {
31+ return & Parser {
3732 headerRegex : headerRegex ,
3833 footerRegex : footerRegex ,
3934 }
4035}
4136
42- func (p * parser ) parse (message string ) (* Commit , error ) {
37+ // Parse attempts to parse a commit message to a conventional commit
38+ func (p * Parser ) Parse (message string ) (* Commit , error ) {
39+ return p .parse (message )
40+ }
41+
42+ func (p * Parser ) parse (message string ) (* Commit , error ) {
4343 c := & Commit {
4444 message : message ,
4545 }
@@ -124,7 +124,7 @@ func (p *parser) parse(message string) (*Commit, error) {
124124
125125// parseLineAsFooter attempts to parse the given line as a footer, returning both the key and the value of the header.
126126// If the line cannot be parsed then isFooter is false
127- func (p * parser ) parseLineAsFooter (line string ) (key , value string , isFooter bool ) {
127+ func (p * Parser ) parseLineAsFooter (line string ) (key , value string , isFooter bool ) {
128128 matches := p .footerRegex .FindStringSubmatch (line )
129129 if len (matches ) != 4 {
130130 return "" , "" , false
@@ -137,7 +137,7 @@ func (p *parser) parseLineAsFooter(line string) (key, value string, isFooter boo
137137}
138138
139139// parseHeader attempts to parse the commit description line and set the appropriate values in the the given commit
140- func (p * parser ) parseHeader (c * Commit , header string ) error {
140+ func (p * Parser ) parseHeader (c * Commit , header string ) error {
141141 matches := p .headerRegex .FindStringSubmatch (header )
142142 if matches == nil {
143143 return errHeader
0 commit comments