Skip to content

Commit 1426a7a

Browse files
committed
parse pr numbers
1 parent 7ff18e8 commit 1426a7a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

routes/github_webhook.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var (
2020
markdownCheckBoxCheckedRegex = regexp.MustCompile(`([ \t]*)[*|-][ \t]{0,4}\[x][ \t]+([^\r\n]+)`)
2121
markdownCheckBoxUncheckedRegex = regexp.MustCompile(`([ \t]*)[*|-][ \t]{0,4}\[ ][ \t]+([^\r\n]+)`)
2222
prURLRegex = regexp.MustCompile(`https?://github\.com/(\w+/\w+)/pull/(\d+)`)
23+
prNumberRegex = regexp.MustCompile(`#(\d+)`)
2324
commitURLRegex = regexp.MustCompile(`https?://github\.com/\w+/\w+/commit/([a-f\d]{7})[a-f\d]+`)
2425
mentionRegex = regexp.MustCompile(`@(\w+)`)
2526
)
@@ -69,7 +70,7 @@ func processReleaseEvent(b *lavalinkbot.Bot, e *github.ReleaseEvent) error {
6970
b.Webhooks[fullName] = webhookClient
7071
}
7172

72-
message := parseMarkdown(e.GetRelease().GetBody())
73+
message := parseMarkdown(e.GetRelease().GetBody(), fullName)
7374
if len(message) > 1024 {
7475
message = substr(message, 0, 1024)
7576
if index := strings.LastIndex(message, "\n"); index != -1 {
@@ -116,12 +117,13 @@ func substr(input string, start int, length int) string {
116117
return string(asRunes[start : start+length])
117118
}
118119

119-
func parseMarkdown(text string) string {
120+
func parseMarkdown(text string, repo string) string {
120121
text = markdownCheckBoxCheckedRegex.ReplaceAllString(text, "$1:ballot_box_with_check: $2")
121122
text = markdownCheckBoxUncheckedRegex.ReplaceAllString(text, "$1:white_square_button: $2")
122123
text = markdownHeaderRegex.ReplaceAllString(text, "**$1**")
123124
text = markdownBulletRegex.ReplaceAllString(text, "$1• $2")
124125
text = prURLRegex.ReplaceAllString(text, "[$1#$2]($0)")
126+
text = prNumberRegex.ReplaceAllString(text, "[#$1](https://github.com/"+repo+"/pull/$1)")
125127
text = commitURLRegex.ReplaceAllString(text, "[`$1`]($0)")
126128
text = mentionRegex.ReplaceAllString(text, "[@$1](https://github.com/$1)")
127129
return text

0 commit comments

Comments
 (0)