@@ -30,7 +30,7 @@ type Footer struct {
3030var (
3131 EMPTY_LINE_PATTERN = regexp .MustCompile (`^\s*$` )
3232 HEADER_PATTERN = regexp .MustCompile (`^(?:fixup!\s*)?(\w*)(\(([\w\$\.\*/-]*)\))?(!?):\s(.*)$` )
33- FOOTER_PATTERN = regexp .MustCompile (`^([\w\s\-]+):\s (.*)$` )
33+ FOOTER_PATTERN = regexp .MustCompile (`^([\w\s\-]+):(.*)$` )
3434 REVERT_HEADER_PATTERN = regexp .MustCompile (`^(?i)revert\s(.*)$` )
3535 REVERT_BODY_PATTERN = regexp .MustCompile (`(?i)This\sreverts\scommit\s(\w+)\.?` )
3636)
@@ -82,8 +82,8 @@ func (m Message) GetFooter() []Footer {
8282 footer .Tag = ""
8383 footer .Title = line
8484 } else {
85- footer .Tag = matcher [1 ]
86- footer .Title = matcher [2 ]
85+ footer .Tag = strings . TrimSpace ( matcher [1 ])
86+ footer .Title = strings . TrimSpace ( matcher [2 ])
8787 }
8888 continue lineLoop
8989 } else {
@@ -197,47 +197,40 @@ func Parse(message string) Message {
197197
198198 previousLine := lines [index - 1 ]
199199
200- // parse body
201- if ! FOOTER_PATTERN .MatchString (line ) {
202- body = append (body , line )
200+ // if is a footer start
201+ if FOOTER_PATTERN .MatchString (line ) && (EMPTY_LINE_PATTERN .MatchString (previousLine ) || FOOTER_PATTERN .MatchString (previousLine )) {
202+ footerContent := []string {line }
203+
203204 index ++
204- continue
205- } else {
206- // if previous line is blank. then should be body block end
207- // or previous line is a footer
208- if EMPTY_LINE_PATTERN .MatchString (previousLine ) || FOOTER_PATTERN .MatchString (previousLine ) {
209- footerContent := []string {line }
210205
211- index ++
206+ // if this line is last line
207+ if index >= len (lines ) {
208+ footer = append (footer , strings .TrimSpace (strings .Join (footerContent , "\n " )))
209+ continue
210+ }
212211
213- // if this line is last line
212+ innerLoop:
213+ for {
214214 if index >= len (lines ) {
215215 footer = append (footer , strings .TrimSpace (strings .Join (footerContent , "\n " )))
216- continue
216+ break innerLoop
217217 }
218218
219- innerLoop:
220- for {
221- if index >= len (lines ) {
222- break innerLoop
223- }
224-
225- line := lines [index ]
226-
227- if ! FOOTER_PATTERN .MatchString (line ) {
228- footerContent = append (footerContent , line )
229- index ++
230- continue innerLoop
231- } else {
232- footer = append (footer , strings .TrimSpace (strings .Join (footerContent , "\n " )))
233- break innerLoop
234- }
219+ line := lines [index ]
220+
221+ if ! FOOTER_PATTERN .MatchString (line ) {
222+ footerContent = append (footerContent , line )
223+ index ++
224+ continue innerLoop
225+ } else {
226+ footer = append (footer , strings .TrimSpace (strings .Join (footerContent , "\n " )))
227+ break innerLoop
235228 }
236- } else {
237- body = append (body , line )
238- index ++
239- continue
240229 }
230+ } else {
231+ body = append (body , line )
232+ index ++
233+ continue
241234 }
242235 }
243236
0 commit comments