--- a/trac/tickets.go Tue Aug 11 23:04:40 2020 -0500
+++ b/trac/tickets.go Mon Aug 17 22:44:53 2020 -0500
@@ -117,8 +117,49 @@
ticketLinkRegex = regexp.MustCompile(`#(\d+)([^\w])`)
+ debianBugRegex = regexp.MustCompile(`\[DebianBug:(\d+)(?:\s([^]]+))?\]`) + gnomeBugRegex = regexp.MustCompile(`\[GnomeBug:(\d+)(?:\s([^]]+))?\]`) +func convertLinks(text string) string { + replaceFunc := func(re *regexp.Regexp, urlFormat string) func(string) string { + return func(original string) string { + parts := re.FindStringSubmatch(original) + url := fmt.Sprintf(urlFormat, parts[1]) + return fmt.Sprintf("[%s](%s)", text, url) + // replace the custom [DebianBug] links with real markdown links + text = debianBugRegex.ReplaceAllStringFunc( + "https://bugs.debian.org/%s", + // replace the custom [GnomeBug] links with real markdown links + text = gnomeBugRegex.ReplaceAllStringFunc( + "https://bugzilla.gnome.org/show_bug.cgi?id=%s", func convertComment(projectID, comment string) string {
if strings.Contains(comment, "{{{") {
// inline code uses the same syntax so we need to do code blocks
@@ -140,6 +181,8 @@
// replace any ticket link references
comment = ticketLinkRegex.ReplaceAllString(comment, projectID+"-$1$2")
+ comment = convertLinks(comment)