| 1 |
// Copyright 2021 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
) |
| 12 |
|
| 13 |
// ListHookDeliveries lists webhook deliveries for a webhook configured in an organization. |
| 14 |
// |
| 15 |
// GitHub API docs: https://docs.github.com/rest/orgs/webhooks#list-deliveries-for-an-organization-webhook |
| 16 |
// |
| 17 |
//meta:operation GET /orgs/{org}/hooks/{hook_id}/deliveries |
| 18 |
func (s *OrganizationsService) ListHookDeliveries(ctx context.Context, org string, id int64, opts *ListCursorOptions) ([]*HookDelivery, *Response, error) { |
| 19 |
u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries", org, id) |
| 20 |
u, err := addOptions(u, opts) |
| 21 |
if err != nil { |
| 22 |
return nil, nil, err |
| 23 |
} |
| 24 |
|
| 25 |
req, err := s.client.NewRequest("GET", u, nil) |
| 26 |
if err != nil { |
| 27 |
return nil, nil, err |
| 28 |
} |
| 29 |
|
| 30 |
deliveries := []*HookDelivery{} |
| 31 |
resp, err := s.client.Do(ctx, req, &deliveries) |
| 32 |
if err != nil { |
| 33 |
return nil, resp, err |
| 34 |
} |
| 35 |
|
| 36 |
return deliveries, resp, nil |
| 37 |
} |
| 38 |
|
| 39 |
// GetHookDelivery returns a delivery for a webhook configured in an organization. |
| 40 |
// |
| 41 |
// GitHub API docs: https://docs.github.com/rest/orgs/webhooks#get-a-webhook-delivery-for-an-organization-webhook |
| 42 |
// |
| 43 |
//meta:operation GET /orgs/{org}/hooks/{hook_id}/deliveries/{delivery_id} |
| 44 |
func (s *OrganizationsService) GetHookDelivery(ctx context.Context, owner string, hookID, deliveryID int64) (*HookDelivery, *Response, error) { |
| 45 |
u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries/%v", owner, hookID, deliveryID) |
| 46 |
req, err := s.client.NewRequest("GET", u, nil) |
| 47 |
if err != nil { |
| 48 |
return nil, nil, err |
| 49 |
} |
| 50 |
|
| 51 |
h := new(HookDelivery) |
| 52 |
resp, err := s.client.Do(ctx, req, h) |
| 53 |
if err != nil { |
| 54 |
return nil, resp, err |
| 55 |
} |
| 56 |
|
| 57 |
return h, resp, nil |
| 58 |
} |
| 59 |
|
| 60 |
// RedeliverHookDelivery redelivers a delivery for a webhook configured in an organization. |
| 61 |
// |
| 62 |
// GitHub API docs: https://docs.github.com/rest/orgs/webhooks#redeliver-a-delivery-for-an-organization-webhook |
| 63 |
// |
| 64 |
//meta:operation POST /orgs/{org}/hooks/{hook_id}/deliveries/{delivery_id}/attempts |
| 65 |
func (s *OrganizationsService) RedeliverHookDelivery(ctx context.Context, owner string, hookID, deliveryID int64) (*HookDelivery, *Response, error) { |
| 66 |
u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries/%v/attempts", owner, hookID, deliveryID) |
| 67 |
req, err := s.client.NewRequest("POST", u, nil) |
| 68 |
if err != nil { |
| 69 |
return nil, nil, err |
| 70 |
} |
| 71 |
|
| 72 |
h := new(HookDelivery) |
| 73 |
resp, err := s.client.Do(ctx, req, h) |
| 74 |
if err != nil { |
| 75 |
return nil, resp, err |
| 76 |
} |
| 77 |
|
| 78 |
return h, resp, nil |
| 79 |
} |