+
Skip to content

Add function for redelivering webhooks #2061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions github/orgs_hooks_deliveries.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,22 @@ func (s *OrganizationsService) GetHookDelivery(ctx context.Context, owner string

return h, resp, nil
}

// RedeliverHookDelivery redelivers a delivery for a webhook configured in an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/orgs#redeliver-a-delivery-for-an-organization-webhook
func (s *OrganizationsService) RedeliverHookDelivery(ctx context.Context, owner string, hookID, deliveryID int64) (*HookDelivery, *Response, error) {
u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries/%v/attempts", owner, hookID, deliveryID)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, nil, err
}

h := new(HookDelivery)
resp, err := s.client.Do(ctx, req, h)
if err != nil {
return nil, resp, err
}

return h, resp, nil
}
44 changes: 44 additions & 0 deletions github/orgs_hooks_deliveries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,47 @@ func TestOrganizationsService_GetHookDelivery_invalidOwner(t *testing.T) {
_, _, err := client.Organizations.GetHookDelivery(ctx, "%", 1, 1)
testURLParseError(t, err)
}

func TestOrganizationsService_RedeliverHookDelivery(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/orgs/o/hooks/1/deliveries/1/attempts", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprint(w, `{"id":1}`)
})

ctx := context.Background()
hook, _, err := client.Organizations.RedeliverHookDelivery(ctx, "o", 1, 1)
if err != nil {
t.Errorf("Organizations.RedeliverHookDelivery returned error: %v", err)
}

want := &HookDelivery{ID: Int64(1)}
if !cmp.Equal(hook, want) {
t.Errorf("Organizations.RedeliverHookDelivery returned %+v, want %+v", hook, want)
}

const methodName = "Rede;overHookDelivery"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Organizations.RedeliverHookDelivery(ctx, "\n", -1, -1)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Organizations.RedeliverHookDelivery(ctx, "o", 1, 1)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestOrganizationsService_RedeliverHookDelivery_invalidOwner(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()

ctx := context.Background()
_, _, err := client.Organizations.RedeliverHookDelivery(ctx, "%", 1, 1)
testURLParseError(t, err)
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载