From 157ceb834295957f632253a75099597e5353444e Mon Sep 17 00:00:00 2001 From: Catherine Date: Thu, 2 Oct 2025 12:41:15 +0000 Subject: [PATCH] Add an HTTP status code workaround for GitHub. --- src/pages.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages.go b/src/pages.go index be09463..a317eb9 100644 --- a/src/pages.go +++ b/src/pages.go @@ -436,10 +436,16 @@ func postPage(w http.ResponseWriter, r *http.Request) error { eventRef := event["ref"].(string) if eventRef != fmt.Sprintf("refs/heads/%s", auth.branch) { + code := http.StatusUnauthorized + if strings.Contains(r.Header.Get("User-Agent"), "GitHub-Hookshot") { + // GitHub has no way to restrict branches for a webhook, and responding with 401 + // for every non-pages branch makes the "Recent Deliveries" tab look awful. + code = http.StatusOK + } http.Error(w, - fmt.Sprintf("ref %s not in allowlist [refs/heads/%v])", + fmt.Sprintf("ref %s not in allowlist [refs/heads/%v]", eventRef, auth.branch), - http.StatusUnauthorized) + code) return nil }