From 5cd8132400e6a2682d9a38a9a98df97e5cabf36b Mon Sep 17 00:00:00 2001 From: ecrupper Date: Wed, 1 Jun 2022 10:54:48 -0500 Subject: [PATCH 1/2] fix(api/hook): handle 202 error for webhook redelivery --- scm/github/webhook.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scm/github/webhook.go b/scm/github/webhook.go index 5b4c42096..d592bd7e8 100644 --- a/scm/github/webhook.go +++ b/scm/github/webhook.go @@ -102,7 +102,13 @@ func (c *client) RedeliverWebhook(ctx context.Context, u *library.User, r *libra } // redeliver the webhook - _, _, err = client.Repositories.RedeliverHookDelivery(ctx, r.GetOrg(), r.GetName(), h.GetWebhookID(), deliveryID) + _, resp, err := client.Repositories.RedeliverHookDelivery(ctx, r.GetOrg(), r.GetName(), h.GetWebhookID(), deliveryID) + + // 202 is an AcceptedError which means GitHub has added the job + // to their queue but do not have a result for us yet. + if resp.StatusCode == 202 { + return nil + } if err != nil { return err From 5cb11734c291573784fe47fe9875e0021a10920a Mon Sep 17 00:00:00 2001 From: ecrupper Date: Wed, 1 Jun 2022 11:36:19 -0500 Subject: [PATCH 2/2] change status code check to error interface check --- scm/github/webhook.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scm/github/webhook.go b/scm/github/webhook.go index d592bd7e8..bfab64893 100644 --- a/scm/github/webhook.go +++ b/scm/github/webhook.go @@ -7,6 +7,7 @@ package github import ( "context" "encoding/json" + "errors" "fmt" "net/http" "strconv" @@ -102,15 +103,16 @@ func (c *client) RedeliverWebhook(ctx context.Context, u *library.User, r *libra } // redeliver the webhook - _, resp, err := client.Repositories.RedeliverHookDelivery(ctx, r.GetOrg(), r.GetName(), h.GetWebhookID(), deliveryID) - - // 202 is an AcceptedError which means GitHub has added the job - // to their queue but do not have a result for us yet. - if resp.StatusCode == 202 { - return nil - } + _, _, err = client.Repositories.RedeliverHookDelivery(ctx, r.GetOrg(), r.GetName(), h.GetWebhookID(), deliveryID) if err != nil { + var acceptedError *github.AcceptedError + // Persist if the status received is a 202 Accepted. This + // means the job was added to the queue for GitHub. + if errors.As(err, &acceptedError) { + return nil + } + return err }