From 08da5c144e90527dd3e7c9f8d4ec412f1aa6e21d Mon Sep 17 00:00:00 2001 From: Josh Soref <2119212+jsoref@users.noreply.github.com> Date: Thu, 21 Mar 2024 10:17:16 -0400 Subject: [PATCH] Strip quotes when truncating --- httplistener/templates.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/httplistener/templates.go b/httplistener/templates.go index db8ae92..6cf3ce8 100644 --- a/httplistener/templates.go +++ b/httplistener/templates.go @@ -3,10 +3,13 @@ package httplistener import ( "bytes" "errors" - "github.com/irccloud/irccat/util" - "gopkg.in/go-playground/webhooks.v5/github" + "regexp" "strings" "text/template" + + "github.com/irccloud/irccat/util" + + "gopkg.in/go-playground/webhooks.v5/github" ) var defaultTemplates = map[string]string{ @@ -39,6 +42,11 @@ func refType(ref string) string { return "" } +func stripQuoteAndTruncate(in string, length int) string { + var quote = regexp.MustCompile(`>.*`) + return util.Truncate(quote.ReplaceAllString(in, ""), length) +} + func truncateSha(sha string) string { if len(sha) < 8 { return "" @@ -62,7 +70,7 @@ func highlightFormat(text string) string { func parseTemplates() *template.Template { funcMap := template.FuncMap{ - "trunc": util.Truncate, + "trunc": stripQuoteAndTruncate, "truncateSha": truncateSha, "refType": refType, "refName": refName,