-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathwebhook.go
601 lines (515 loc) · 18.9 KB
/
webhook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
// SPDX-License-Identifier: Apache-2.0
package github
import (
"context"
"encoding/json"
"errors"
"fmt"
"mime"
"net/http"
"strconv"
"strings"
"time"
"github.com/google/go-github/v65/github"
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/internal"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
)
// ProcessWebhook parses the webhook from a repo.
//
//nolint:nilerr // ignore webhook returning nil
func (c *client) ProcessWebhook(ctx context.Context, request *http.Request) (*internal.Webhook, error) {
c.Logger.Tracef("processing GitHub webhook")
// create our own record of the hook and populate its fields
h := new(api.Hook)
h.SetNumber(1)
h.SetSourceID(request.Header.Get("X-GitHub-Delivery"))
hookID, err := strconv.Atoi(request.Header.Get("X-GitHub-Hook-ID"))
if err != nil {
return nil, fmt.Errorf("unable to convert hook id to int64: %w", err)
}
h.SetWebhookID(int64(hookID))
h.SetCreated(time.Now().UTC().Unix())
h.SetHost("github.com")
h.SetEvent(request.Header.Get("X-GitHub-Event"))
h.SetStatus(constants.StatusSuccess)
if len(request.Header.Get("X-GitHub-Enterprise-Host")) > 0 {
h.SetHost(request.Header.Get("X-GitHub-Enterprise-Host"))
}
// get content type
contentType, _, err := mime.ParseMediaType(request.Header.Get("Content-Type"))
if err != nil {
return nil, err
}
payload, err := github.ValidatePayloadFromBody(contentType, request.Body, "", nil)
if err != nil {
return &internal.Webhook{Hook: h}, nil
}
// parse the payload from the webhook
event, err := github.ParseWebHook(github.WebHookType(request), payload)
if err != nil {
return &internal.Webhook{Hook: h}, nil
}
// process the event from the webhook
switch event := event.(type) {
case *github.PushEvent:
return c.processPushEvent(ctx, h, event)
case *github.PullRequestEvent:
return c.processPREvent(h, event)
case *github.DeploymentEvent:
return c.processDeploymentEvent(h, event)
case *github.IssueCommentEvent:
return c.processIssueCommentEvent(h, event)
case *github.RepositoryEvent:
return c.processRepositoryEvent(h, event)
}
return &internal.Webhook{Hook: h}, nil
}
// VerifyWebhook verifies the webhook from a repo.
func (c *client) VerifyWebhook(ctx context.Context, request *http.Request, r *api.Repo) error {
c.Logger.WithFields(logrus.Fields{
"org": r.GetOrg(),
"repo": r.GetName(),
}).Tracef("verifying GitHub webhook for %s", r.GetFullName())
_, err := github.ValidatePayload(request, []byte(r.GetHash()))
if err != nil {
return err
}
return nil
}
// RedeliverWebhook redelivers webhooks from GitHub.
func (c *client) RedeliverWebhook(ctx context.Context, u *api.User, h *api.Hook) error {
// create GitHub OAuth client with user's token
client := c.newClientToken(ctx, u.GetToken())
// capture the delivery ID of the hook using GitHub API
deliveryID, err := c.getDeliveryID(ctx, client, h)
if err != nil {
return err
}
// redeliver the webhook
_, _, err = client.Repositories.RedeliverHookDelivery(
ctx,
h.GetRepo().GetOrg(),
h.GetRepo().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
}
return nil
}
// processPushEvent is a helper function to process the push event.
func (c *client) processPushEvent(ctx context.Context, h *api.Hook, payload *github.PushEvent) (*internal.Webhook, error) {
c.Logger.WithFields(logrus.Fields{
"org": payload.GetRepo().GetOwner().GetLogin(),
"repo": payload.GetRepo().GetName(),
}).Tracef("processing push GitHub webhook for %s", payload.GetRepo().GetFullName())
repo := payload.GetRepo()
if repo == nil {
return &internal.Webhook{Hook: h}, nil
}
// convert payload to library repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
r.SetFullName(repo.GetFullName())
r.SetLink(repo.GetHTMLURL())
r.SetClone(repo.GetCloneURL())
r.SetBranch(repo.GetDefaultBranch())
r.SetPrivate(repo.GetPrivate())
r.SetTopics(repo.Topics)
// convert payload to library build
b := new(api.Build)
b.SetEvent(constants.EventPush)
b.SetClone(repo.GetCloneURL())
b.SetSource(payload.GetHeadCommit().GetURL())
b.SetTitle(fmt.Sprintf("%s received from %s", constants.EventPush, repo.GetHTMLURL()))
b.SetMessage(payload.GetHeadCommit().GetMessage())
b.SetCommit(payload.GetHeadCommit().GetID())
b.SetSender(payload.GetSender().GetLogin())
b.SetSenderSCMID(fmt.Sprint(payload.GetSender().GetID()))
b.SetAuthor(payload.GetHeadCommit().GetAuthor().GetLogin())
b.SetEmail(payload.GetHeadCommit().GetAuthor().GetEmail())
b.SetBranch(strings.TrimPrefix(payload.GetRef(), "refs/heads/"))
b.SetRef(payload.GetRef())
b.SetBaseRef(payload.GetBaseRef())
// update the hook object
h.SetBranch(b.GetBranch())
h.SetEvent(constants.EventPush)
h.SetLink(
fmt.Sprintf("https://%s/%s/settings/hooks", h.GetHost(), r.GetFullName()),
)
// ensure the build author is set
if len(b.GetAuthor()) == 0 {
b.SetAuthor(payload.GetHeadCommit().GetCommitter().GetName())
}
// ensure the build sender is set
if len(b.GetSender()) == 0 {
b.SetSender(payload.GetPusher().GetName())
}
// ensure the build email is set
if len(b.GetEmail()) == 0 {
b.SetEmail(payload.GetHeadCommit().GetCommitter().GetEmail())
}
// handle when push event is a tag
if strings.HasPrefix(b.GetRef(), "refs/tags/") {
// set the proper event for the hook
h.SetEvent(constants.EventTag)
// set the proper event for the build
b.SetEvent(constants.EventTag)
// set the proper branch from the base ref
if strings.HasPrefix(payload.GetBaseRef(), "refs/heads/") {
b.SetBranch(strings.TrimPrefix(payload.GetBaseRef(), "refs/heads/"))
}
}
// handle when push event is a delete
if strings.EqualFold(b.GetCommit(), "") {
b.SetCommit(payload.GetBefore())
b.SetRef(payload.GetBefore())
b.SetTitle(fmt.Sprintf("%s received from %s", constants.EventDelete, repo.GetHTMLURL()))
b.SetAuthor(payload.GetSender().GetLogin())
b.SetSource(fmt.Sprintf("%s/commit/%s", payload.GetRepo().GetHTMLURL(), payload.GetBefore()))
b.SetEmail(payload.GetPusher().GetEmail())
// set the proper event for the hook
h.SetEvent(constants.EventDelete)
// set the proper event for the build
b.SetEvent(constants.EventDelete)
if strings.HasPrefix(payload.GetRef(), "refs/tags/") {
b.SetBranch(strings.TrimPrefix(payload.GetRef(), "refs/tags/"))
// set the proper action for the build
b.SetEventAction(constants.ActionTag)
// set the proper message for the build
b.SetMessage(fmt.Sprintf("%s %s deleted", strings.TrimPrefix(payload.GetRef(), "refs/tags/"), constants.ActionTag))
} else {
// set the proper action for the build
b.SetEventAction(constants.ActionBranch)
// set the proper message for the build
b.SetMessage(fmt.Sprintf("%s %s deleted", strings.TrimPrefix(payload.GetRef(), "refs/heads/"), constants.ActionBranch))
}
}
return &internal.Webhook{
Hook: h,
Repo: r,
Build: b,
}, nil
}
// processPREvent is a helper function to process the pull_request event.
func (c *client) processPREvent(h *api.Hook, payload *github.PullRequestEvent) (*internal.Webhook, error) {
c.Logger.WithFields(logrus.Fields{
"org": payload.GetRepo().GetOwner().GetLogin(),
"repo": payload.GetRepo().GetName(),
}).Tracef("processing pull_request GitHub webhook for %s", payload.GetRepo().GetFullName())
// update the hook object
h.SetBranch(payload.GetPullRequest().GetBase().GetRef())
h.SetEvent(constants.EventPull)
h.SetLink(
fmt.Sprintf("https://%s/%s/settings/hooks", h.GetHost(), payload.GetRepo().GetFullName()),
)
// if the pull request state isn't open we ignore it
if payload.GetPullRequest().GetState() != "open" {
return &internal.Webhook{Hook: h}, nil
}
// skip if the pull request action is not opened, synchronize, reopened, edited, labeled, or unlabeled
if !strings.EqualFold(payload.GetAction(), "opened") &&
!strings.EqualFold(payload.GetAction(), "synchronize") &&
!strings.EqualFold(payload.GetAction(), "reopened") &&
!strings.EqualFold(payload.GetAction(), "edited") &&
!strings.EqualFold(payload.GetAction(), "labeled") &&
!strings.EqualFold(payload.GetAction(), "unlabeled") {
return &internal.Webhook{Hook: h}, nil
}
// capture the repo from the payload
repo := payload.GetRepo()
if repo == nil {
return &internal.Webhook{Hook: h}, nil
}
// convert payload to library repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
r.SetFullName(repo.GetFullName())
r.SetLink(repo.GetHTMLURL())
r.SetClone(repo.GetCloneURL())
r.SetBranch(repo.GetDefaultBranch())
r.SetPrivate(repo.GetPrivate())
r.SetTopics(repo.Topics)
// convert payload to api build
b := new(api.Build)
b.SetEvent(constants.EventPull)
b.SetEventAction(payload.GetAction())
b.SetClone(repo.GetCloneURL())
b.SetSource(payload.GetPullRequest().GetHTMLURL())
b.SetTitle(fmt.Sprintf("%s received from %s", constants.EventPull, repo.GetHTMLURL()))
b.SetMessage(payload.GetPullRequest().GetTitle())
b.SetCommit(payload.GetPullRequest().GetHead().GetSHA())
b.SetSender(payload.GetSender().GetLogin())
b.SetSenderSCMID(fmt.Sprint(payload.GetSender().GetID()))
b.SetAuthor(payload.GetPullRequest().GetUser().GetLogin())
b.SetEmail(payload.GetPullRequest().GetUser().GetEmail())
b.SetBranch(payload.GetPullRequest().GetBase().GetRef())
b.SetRef(fmt.Sprintf("refs/pull/%d/head", payload.GetNumber()))
b.SetBaseRef(payload.GetPullRequest().GetBase().GetRef())
b.SetHeadRef(payload.GetPullRequest().GetHead().GetRef())
// ensure the build reference is set
if payload.GetPullRequest().GetMerged() {
b.SetRef(fmt.Sprintf("refs/pull/%d/merge", payload.GetNumber()))
}
// ensure the build author is set
if len(b.GetAuthor()) == 0 {
b.SetAuthor(payload.GetPullRequest().GetHead().GetUser().GetLogin())
}
// ensure the build sender is set
if len(b.GetSender()) == 0 {
b.SetSender(payload.GetPullRequest().GetUser().GetLogin())
b.SetSenderSCMID(fmt.Sprint(payload.GetPullRequest().GetUser().GetID()))
}
// ensure the build email is set
if len(b.GetEmail()) == 0 {
b.SetEmail(payload.GetPullRequest().GetHead().GetUser().GetEmail())
}
var prLabels []string
if strings.EqualFold(payload.GetAction(), "labeled") ||
strings.EqualFold(payload.GetAction(), "unlabeled") {
prLabels = append(prLabels, payload.GetLabel().GetName())
} else {
labels := payload.GetPullRequest().Labels
for _, label := range labels {
prLabels = append(prLabels, label.GetName())
}
}
// determine if pull request head is a fork and does not match the repo name of base
fromFork := payload.GetPullRequest().GetHead().GetRepo().GetFork() &&
!strings.EqualFold(payload.GetPullRequest().GetBase().GetRepo().GetFullName(), payload.GetPullRequest().GetHead().GetRepo().GetFullName())
return &internal.Webhook{
PullRequest: internal.PullRequest{
Number: payload.GetNumber(),
IsFromFork: fromFork,
Labels: prLabels,
},
Hook: h,
Repo: r,
Build: b,
}, nil
}
// processDeploymentEvent is a helper function to process the deployment event.
func (c *client) processDeploymentEvent(h *api.Hook, payload *github.DeploymentEvent) (*internal.Webhook, error) {
c.Logger.WithFields(logrus.Fields{
"org": payload.GetRepo().GetOwner().GetLogin(),
"repo": payload.GetRepo().GetName(),
}).Tracef("processing deployment GitHub webhook for %s", payload.GetRepo().GetFullName())
// capture the repo from the payload
repo := payload.GetRepo()
if repo == nil {
return &internal.Webhook{Hook: h}, nil
}
// convert payload to library repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
r.SetFullName(repo.GetFullName())
r.SetLink(repo.GetHTMLURL())
r.SetClone(repo.GetCloneURL())
r.SetBranch(repo.GetDefaultBranch())
r.SetPrivate(repo.GetPrivate())
r.SetTopics(repo.Topics)
// convert payload to api build
b := new(api.Build)
b.SetEvent(constants.EventDeploy)
b.SetEventAction(constants.ActionCreated)
b.SetClone(repo.GetCloneURL())
b.SetDeploy(payload.GetDeployment().GetEnvironment())
b.SetDeployNumber(payload.GetDeployment().GetID())
b.SetSource(payload.GetDeployment().GetURL())
b.SetTitle(fmt.Sprintf("%s received from %s", constants.EventDeploy, repo.GetHTMLURL()))
b.SetMessage(payload.GetDeployment().GetDescription())
b.SetCommit(payload.GetDeployment().GetSHA())
b.SetSender(payload.GetSender().GetLogin())
b.SetSenderSCMID(fmt.Sprint(payload.GetSender().GetID()))
b.SetAuthor(payload.GetDeployment().GetCreator().GetLogin())
b.SetEmail(payload.GetDeployment().GetCreator().GetEmail())
b.SetBranch(payload.GetDeployment().GetRef())
b.SetRef(payload.GetDeployment().GetRef())
d := new(library.Deployment)
d.SetNumber(payload.GetDeployment().GetID())
d.SetURL(payload.GetDeployment().GetURL())
d.SetCommit(payload.GetDeployment().GetSHA())
d.SetRef(b.GetRef())
d.SetTask(payload.GetDeployment().GetTask())
d.SetTarget(payload.GetDeployment().GetEnvironment())
d.SetDescription(payload.GetDeployment().GetDescription())
d.SetCreatedAt(time.Now().Unix())
d.SetCreatedBy(payload.GetDeployment().GetCreator().GetLogin())
// check if payload is provided within request
//
// use a length of 2 because the payload will
// never be nil even if no payload is provided.
//
// sending an API request to GitHub with no
// payload provided yields a default of `{}`.
if len(payload.GetDeployment().Payload) > 2 {
deployPayload := make(map[string]string)
// unmarshal the payload into the expected map[string]string format
err := json.Unmarshal(payload.GetDeployment().Payload, &deployPayload)
if err != nil {
return &internal.Webhook{}, err
}
// check if the map is empty
if len(deployPayload) != 0 {
// set the payload info on the build
b.SetDeployPayload(deployPayload)
}
}
// handle when the ref is a sha or short sha
if strings.HasPrefix(b.GetCommit(), b.GetRef()) || b.GetCommit() == b.GetRef() {
// set the proper branch for the build
b.SetBranch(r.GetBranch())
// set the proper ref for the build
b.SetRef(fmt.Sprintf("refs/heads/%s", b.GetBranch()))
}
// handle when the ref is a branch
if !strings.HasPrefix(b.GetRef(), "refs/") {
// set the proper ref for the build
b.SetRef(fmt.Sprintf("refs/heads/%s", b.GetBranch()))
}
// update the hook object
h.SetBranch(b.GetBranch())
h.SetEvent(constants.EventDeploy)
h.SetEventAction(constants.ActionCreated)
h.SetLink(
fmt.Sprintf("https://%s/%s/settings/hooks", h.GetHost(), r.GetFullName()),
)
return &internal.Webhook{
Hook: h,
Repo: r,
Build: b,
Deployment: d,
}, nil
}
// processIssueCommentEvent is a helper function to process the issue comment event.
func (c *client) processIssueCommentEvent(h *api.Hook, payload *github.IssueCommentEvent) (*internal.Webhook, error) {
c.Logger.WithFields(logrus.Fields{
"org": payload.GetRepo().GetOwner().GetLogin(),
"repo": payload.GetRepo().GetName(),
}).Tracef("processing issue_comment GitHub webhook for %s", payload.GetRepo().GetFullName())
// update the hook object
h.SetEvent(constants.EventComment)
h.SetLink(
fmt.Sprintf("https://%s/%s/settings/hooks", h.GetHost(), payload.GetRepo().GetFullName()),
)
// skip if the comment action is deleted or not part of a pull request
if strings.EqualFold(payload.GetAction(), "deleted") || !payload.GetIssue().IsPullRequest() {
// return &internal.Webhook{Hook: h}, nil
return &internal.Webhook{
Hook: h,
}, nil
}
// capture the repo from the payload
repo := payload.GetRepo()
if repo == nil {
return &internal.Webhook{Hook: h}, nil
}
// convert payload to library repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
r.SetFullName(repo.GetFullName())
r.SetLink(repo.GetHTMLURL())
r.SetClone(repo.GetCloneURL())
r.SetBranch(repo.GetDefaultBranch())
r.SetPrivate(repo.GetPrivate())
r.SetTopics(repo.Topics)
// convert payload to library build
b := new(api.Build)
b.SetEvent(constants.EventComment)
b.SetEventAction(payload.GetAction())
b.SetClone(repo.GetCloneURL())
b.SetSource(payload.Issue.GetHTMLURL())
b.SetTitle(fmt.Sprintf("%s received from %s", constants.EventComment, repo.GetHTMLURL()))
b.SetMessage(payload.Issue.GetTitle())
b.SetSender(payload.GetSender().GetLogin())
b.SetSenderSCMID(fmt.Sprint(payload.GetSender().GetID()))
b.SetAuthor(payload.GetIssue().GetUser().GetLogin())
b.SetEmail(payload.GetIssue().GetUser().GetEmail())
b.SetRef(fmt.Sprintf("refs/pull/%d/head", payload.GetIssue().GetNumber()))
return &internal.Webhook{
PullRequest: internal.PullRequest{
Comment: payload.GetComment().GetBody(),
Number: payload.GetIssue().GetNumber(),
},
Hook: h,
Repo: r,
Build: b,
}, nil
}
// processRepositoryEvent is a helper function to process the repository event.
func (c *client) processRepositoryEvent(h *api.Hook, payload *github.RepositoryEvent) (*internal.Webhook, error) {
logrus.Tracef("processing repository event GitHub webhook for %s", payload.GetRepo().GetFullName())
repo := payload.GetRepo()
if repo == nil {
return &internal.Webhook{Hook: h}, nil
}
// convert payload to library repo
r := new(api.Repo)
r.SetOrg(repo.GetOwner().GetLogin())
r.SetName(repo.GetName())
r.SetFullName(repo.GetFullName())
r.SetLink(repo.GetHTMLURL())
r.SetClone(repo.GetCloneURL())
r.SetBranch(repo.GetDefaultBranch())
r.SetPrivate(repo.GetPrivate())
r.SetActive(!repo.GetArchived())
r.SetTopics(repo.Topics)
h.SetEvent(constants.EventRepository)
h.SetEventAction(payload.GetAction())
h.SetBranch(r.GetBranch())
h.SetLink(
fmt.Sprintf("https://%s/%s/settings/hooks", h.GetHost(), r.GetFullName()),
)
return &internal.Webhook{
Hook: h,
Repo: r,
}, nil
}
// getDeliveryID gets the last 100 webhook deliveries for a repo and
// finds the matching delivery id with the source id in the hook.
func (c *client) getDeliveryID(ctx context.Context, ghClient *github.Client, h *api.Hook) (int64, error) {
c.Logger.WithFields(logrus.Fields{
"org": h.GetRepo().GetOrg(),
"repo": h.GetRepo().GetName(),
}).Tracef("searching for delivery id for hook: %s", h.GetSourceID())
// set per page to 100 to retrieve last 100 hook summaries
opt := &github.ListCursorOptions{PerPage: 100}
// send API call to capture delivery summaries that contain Delivery ID value
deliveries, resp, err := ghClient.Repositories.ListHookDeliveries(
ctx,
h.GetRepo().GetOrg(),
h.GetRepo().GetName(),
h.GetWebhookID(),
opt,
)
// version check: if GitHub API is older than version 3.2, this call will not work
if resp.StatusCode == 415 {
err = fmt.Errorf("requires GitHub version 3.2 or later")
return 0, err
}
if err != nil {
return 0, err
}
// cycle through delivery summaries and match Source ID/GUID. Capture Delivery ID
for _, delivery := range deliveries {
if delivery.GetGUID() == h.GetSourceID() {
return delivery.GetID(), nil
}
}
// if not found, webhook was not recent enough for GitHub
err = fmt.Errorf("webhook no longer available to be redelivered")
return 0, err
}