File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232 HEADER_PATTERN = regexp .MustCompile (`^(?:fixup!\s*)?(\w*)(\(([\w\$\.\*/-]*)\))?(!?):\s(.*)$` )
3333 FOOTER_PATTERN = regexp .MustCompile (`^([\w\s\-]+):\s(.*)$` )
3434 REVERT_HEADER_PATTERN = regexp .MustCompile (`^(?i)revert\s(.*)$` )
35+ REVERT_BODY_PATTERN = regexp .MustCompile (`^(?i)This\sreverts\scommit\s(\w+)\.?$` )
3536)
3637
3738func splitToLines (text string ) []string {
@@ -95,6 +96,25 @@ func (m Message) GetFooter() []Footer {
9596 footers = append (footers , footer )
9697 }
9798
99+ header := m .GetHeader ()
100+
101+ if header .Type == "revert" {
102+ matcher := REVERT_BODY_PATTERN .FindStringSubmatch (m .Body )
103+ content := ""
104+
105+ if len (matcher ) > 0 {
106+ content = matcher [1 ]
107+ }
108+
109+ footer := Footer {
110+ Tag : "revert" ,
111+ Title : m .Body ,
112+ Content : content ,
113+ }
114+
115+ footers = append (footers , footer )
116+ }
117+
98118 return footers
99119}
100120
@@ -170,6 +190,7 @@ func Parse(message string) Message {
170190
171191 // The second line should be blank
172192 if index == 1 {
193+ body = append (body , line )
173194 index ++
174195 continue
175196 }
Original file line number Diff line number Diff line change @@ -17,6 +17,31 @@ func TestParse(t *testing.T) {
1717 header Header
1818 footer []Footer
1919 }{
20+ {
21+ name : "revert commit" ,
22+ args : args {
23+ message : `Revert "deprecated"
24+ This reverts commit bf08694.` ,
25+ },
26+ want : Message {
27+ Header : `Revert "deprecated"` ,
28+ Body : "This reverts commit bf08694." ,
29+ Footer : []string {},
30+ },
31+ header : Header {
32+ Type : "revert" ,
33+ Scope : "" ,
34+ Subject : "deprecated" ,
35+ Important : false ,
36+ },
37+ footer : []Footer {
38+ {
39+ Tag : "revert" ,
40+ Title : "This reverts commit bf08694." ,
41+ Content : "bf08694" ,
42+ },
43+ },
44+ },
2045 {
2146 name : "common commit" ,
2247 args : args {
You can’t perform that action at this time.
0 commit comments