-
Notifications
You must be signed in to change notification settings - Fork 0
/
footer.go
80 lines (63 loc) · 1.75 KB
/
footer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package conventionalcommitparser
import (
"regexp"
"strings"
)
type Footer struct {
Tag string
Title string
Content string
}
var (
footerTagPattern = regexp.MustCompile(`(?i)^([a-z]+(-[a-z]+)*):\s?(.*)$`)
footerHashPattern = regexp.MustCompile(`^(?i)^([\w\-]+)\s+(#.*)`)
footerBreakingChangePattern = regexp.MustCompile(`^(BREAKING\sCHANGE):\s*(.*)$`)
)
func paseFooterParagraph(txt string) Footer {
footer := Footer{}
tagMatcher := footerTagPattern.FindStringSubmatch(txt)
breakingChangeMatcher := footerBreakingChangePattern.FindStringSubmatch(txt)
hashTagMatcher := footerHashPattern.FindStringSubmatch(txt)
if len(breakingChangeMatcher) != 0 {
footer.Tag = strings.TrimSpace(breakingChangeMatcher[1])
footer.Title = strings.TrimSpace(breakingChangeMatcher[2])
} else if len(tagMatcher) != 0 {
footer.Tag = strings.TrimSpace(tagMatcher[1])
footer.Title = strings.TrimSpace(tagMatcher[3])
} else if len(hashTagMatcher) != 0 {
footer.Tag = strings.TrimSpace(hashTagMatcher[1])
footer.Title = strings.TrimSpace(hashTagMatcher[2])
} else {
footer.Tag = ""
footer.Title = txt
}
return footer
}
func isFooterParagraph(txt string) bool {
if footerBreakingChangePattern.MatchString(txt) {
return true
}
if footerTagPattern.MatchString(txt) {
return true
}
if footerHashPattern.MatchString(txt) {
return true
}
return false
}
func parseFooter(txt string) Footer {
lines := splitToLines(txt)
footer := Footer{}
contents := make([]string, 0)
lineLoop:
for index, line := range lines {
if index == 0 {
footer = paseFooterParagraph(line)
continue lineLoop
} else {
contents = append(contents, line)
}
}
footer.Content = strings.TrimSpace(strings.Join(contents, "\n"))
return footer
}