|
20 | 20 | markdownCheckBoxCheckedRegex = regexp.MustCompile(`([ \t]*)[*|-][ \t]{0,4}\[x][ \t]+([^\r\n]+)`)
|
21 | 21 | markdownCheckBoxUncheckedRegex = regexp.MustCompile(`([ \t]*)[*|-][ \t]{0,4}\[ ][ \t]+([^\r\n]+)`)
|
22 | 22 | prURLRegex = regexp.MustCompile(`https?://github\.com/(\w+/\w+)/pull/(\d+)`)
|
| 23 | + prNumberRegex = regexp.MustCompile(`#(\d+)`) |
23 | 24 | commitURLRegex = regexp.MustCompile(`https?://github\.com/\w+/\w+/commit/([a-f\d]{7})[a-f\d]+`)
|
24 | 25 | mentionRegex = regexp.MustCompile(`@(\w+)`)
|
25 | 26 | )
|
@@ -69,7 +70,7 @@ func processReleaseEvent(b *lavalinkbot.Bot, e *github.ReleaseEvent) error {
|
69 | 70 | b.Webhooks[fullName] = webhookClient
|
70 | 71 | }
|
71 | 72 |
|
72 |
| - message := parseMarkdown(e.GetRelease().GetBody()) |
| 73 | + message := parseMarkdown(e.GetRelease().GetBody(), fullName) |
73 | 74 | if len(message) > 1024 {
|
74 | 75 | message = substr(message, 0, 1024)
|
75 | 76 | if index := strings.LastIndex(message, "\n"); index != -1 {
|
@@ -116,12 +117,13 @@ func substr(input string, start int, length int) string {
|
116 | 117 | return string(asRunes[start : start+length])
|
117 | 118 | }
|
118 | 119 |
|
119 |
| -func parseMarkdown(text string) string { |
| 120 | +func parseMarkdown(text string, repo string) string { |
120 | 121 | text = markdownCheckBoxCheckedRegex.ReplaceAllString(text, "$1:ballot_box_with_check: $2")
|
121 | 122 | text = markdownCheckBoxUncheckedRegex.ReplaceAllString(text, "$1:white_square_button: $2")
|
122 | 123 | text = markdownHeaderRegex.ReplaceAllString(text, "**$1**")
|
123 | 124 | text = markdownBulletRegex.ReplaceAllString(text, "$1• $2")
|
124 | 125 | text = prURLRegex.ReplaceAllString(text, "[$1#$2]($0)")
|
| 126 | + text = prNumberRegex.ReplaceAllString(text, "[#$1](https://github.com/"+repo+"/pull/$1)") |
125 | 127 | text = commitURLRegex.ReplaceAllString(text, "[`$1`]($0)")
|
126 | 128 | text = mentionRegex.ReplaceAllString(text, "[@$1](https://github.com/$1)")
|
127 | 129 | return text
|
|
0 commit comments