From 2e9afc6435a608d3f36e64b8a8aeeb0e7abbd820 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 12 Aug 2020 08:20:20 -0400 Subject: [PATCH] gitsrht-update-hook: strip ANSI from webhook output --- gitsrht-update-hook/webhooks.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gitsrht-update-hook/webhooks.go b/gitsrht-update-hook/webhooks.go index d39561e..fd720c9 100644 --- a/gitsrht-update-hook/webhooks.go +++ b/gitsrht-update-hook/webhooks.go @@ -9,6 +9,8 @@ import ( "io/ioutil" "log" "net/http" + "net/url" + "regexp" "strings" "time" "unicode/utf8" @@ -68,6 +70,8 @@ func initWebhookKey() { privkey = ed25519.NewKeyFromSeed(seed) } +var ansi = regexp.MustCompile("\x1B\\[[0-?]*[ -/]*[@-~]") + func deliverWebhooks(subs []WebhookSubscription, payload []byte, printResponse bool) []WebhookDelivery { @@ -135,7 +139,10 @@ func deliverWebhooks(subs []WebhookSubscription, continue } if printResponse { - log.Println(runewidth.Truncate(string(respBody), 1024, "...")) + u, _ := url.Parse(sub.Url) // Errors will have happened earlier + log.Println("Response from %s:", u.Host) + log.Println(runewidth.Truncate(ansi.ReplaceAllString( + string(respBody), ""), 1024, "...")) } logger.Printf("Delivered webhook to %s (sub %d), got %d", sub.Url, sub.Id, resp.StatusCode) -- 2.38.4