-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add support for listing and getting repository/organization webhook deliveries #1934
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
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
54e5502
Add support for listing and getting repository webhook deliveries
mumoshu f5889f8
Add test for HookDelivery.ParseRequestPayload
mumoshu f6d688a
Restructure populatePageValues to reduce nesting
mumoshu ff5a47a
Use Timestamp instead of time.Time for delivered_at
mumoshu dffbb1c
Fix HookResponse.Header to Headers for consistency with the underlyin…
mumoshu 5f0e1e4
Use %v instead of %d for formatting int64
mumoshu 431c77c
Add more tests for ParseRequestPayload
mumoshu 23922a8
Enhance cursor pagination test for more coverage
mumoshu 72c3380
Make it clear that cursor and page are mutually exclusive
mumoshu 5b86aff
Add periods to field comments
mumoshu 194eff6
Add comments on HookRequest and HookResponse
mumoshu 1381c0f
Accept suggestions from gmlewis with thanks :)
mumoshu 0a3739c
Add support for listing and getting organization webhook deliveries
mumoshu fc8d20f
Add copyright notice to orgs_hooks_deliveries.go
mumoshu 123bafa
Add blank after if err block for consistency
mumoshu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add support for listing and getting organization webhook deliveries
Ref #1933
- Loading branch information
commit 0a3739c94ba1eb5fe9f040f465b1e5387eb802e1
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| ) | ||
|
|
||
| // ListHookDeliveries lists webhook deliveries for a webhook configured in an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/reference/orgs#list-deliveries-for-an-organization-webhook | ||
| func (s *OrganizationsService) ListHookDeliveries(ctx context.Context, org string, id int64, opts *ListCursorOptions) ([]*HookDelivery, *Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries", org, id) | ||
| u, err := addOptions(u, opts) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
|
|
||
| deliveries := []*HookDelivery{} | ||
| resp, err := s.client.Do(ctx, req, &deliveries) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return deliveries, resp, nil | ||
| } | ||
|
|
||
| // GetHookDelivery returns a delivery for a webhook configured in an organization. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/en/rest/reference/orgs#get-a-webhook-delivery-for-an-organization-webhook | ||
| func (s *OrganizationsService) GetHookDelivery(ctx context.Context, owner string, hookID, deliveryID int64) (*HookDelivery, *Response, error) { | ||
| u := fmt.Sprintf("orgs/%v/hooks/%v/deliveries/%v", owner, hookID, deliveryID) | ||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| h := new(HookDelivery) | ||
gmlewis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| resp, err := s.client.Do(ctx, req, h) | ||
| if err != nil { | ||
| return nil, resp, err | ||
| } | ||
|
|
||
| return h, resp, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // Copyright 2021 The go-github AUTHORS. All rights reserved. | ||
| // | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| func TestOrganizationsService_ListHookDeliveries(t *testing.T) { | ||
| client, mux, _, teardown := setup() | ||
| defer teardown() | ||
|
|
||
| mux.HandleFunc("/orgs/o/hooks/1/deliveries", func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "GET") | ||
| testFormValues(t, r, values{"cursor": "v1_12077215967"}) | ||
| fmt.Fprint(w, `[{"id":1}, {"id":2}]`) | ||
| }) | ||
|
|
||
| opt := &ListCursorOptions{Cursor: "v1_12077215967"} | ||
|
|
||
| ctx := context.Background() | ||
| hooks, _, err := client.Organizations.ListHookDeliveries(ctx, "o", 1, opt) | ||
| if err != nil { | ||
| t.Errorf("Organizations.ListHookDeliveries returned error: %v", err) | ||
| } | ||
|
|
||
| want := []*HookDelivery{{ID: Int64(1)}, {ID: Int64(2)}} | ||
| if d := cmp.Diff(hooks, want); d != "" { | ||
| t.Errorf("Organizations.ListHooks want (-), got (+):\n%s", d) | ||
| } | ||
|
|
||
| const methodName = "ListHookDeliveries" | ||
| testBadOptions(t, methodName, func() (err error) { | ||
| _, _, err = client.Organizations.ListHookDeliveries(ctx, "\n", -1, opt) | ||
| return err | ||
| }) | ||
|
|
||
| testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
| got, resp, err := client.Organizations.ListHookDeliveries(ctx, "o", 1, opt) | ||
| if got != nil { | ||
| t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) | ||
| } | ||
| return resp, err | ||
| }) | ||
| } | ||
|
|
||
| func TestOrganizationsService_ListHookDeliveries_invalidOwner(t *testing.T) { | ||
| client, _, _, teardown := setup() | ||
| defer teardown() | ||
|
|
||
| ctx := context.Background() | ||
| _, _, err := client.Organizations.ListHookDeliveries(ctx, "%", 1, nil) | ||
| testURLParseError(t, err) | ||
| } | ||
|
|
||
| func TestOrganizationsService_GetHookDelivery(t *testing.T) { | ||
| client, mux, _, teardown := setup() | ||
| defer teardown() | ||
|
|
||
| mux.HandleFunc("/orgs/o/hooks/1/deliveries/1", func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "GET") | ||
| fmt.Fprint(w, `{"id":1}`) | ||
| }) | ||
|
|
||
| ctx := context.Background() | ||
| hook, _, err := client.Organizations.GetHookDelivery(ctx, "o", 1, 1) | ||
| if err != nil { | ||
| t.Errorf("Organizations.GetHookDelivery returned error: %v", err) | ||
| } | ||
|
|
||
| want := &HookDelivery{ID: Int64(1)} | ||
| if !cmp.Equal(hook, want) { | ||
| t.Errorf("Organizations.GetHookDelivery returned %+v, want %+v", hook, want) | ||
| } | ||
|
|
||
| const methodName = "GetHookDelivery" | ||
| testBadOptions(t, methodName, func() (err error) { | ||
| _, _, err = client.Organizations.GetHookDelivery(ctx, "\n", -1, -1) | ||
| return err | ||
| }) | ||
|
|
||
| testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
| got, resp, err := client.Organizations.GetHookDelivery(ctx, "o", 1, 1) | ||
| if got != nil { | ||
| t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) | ||
| } | ||
| return resp, err | ||
| }) | ||
| } | ||
|
|
||
| func TestOrganizationsService_GetHookDelivery_invalidOwner(t *testing.T) { | ||
| client, _, _, teardown := setup() | ||
| defer teardown() | ||
|
|
||
| ctx := context.Background() | ||
| _, _, err := client.Organizations.GetHookDelivery(ctx, "%", 1, 1) | ||
| testURLParseError(t, err) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.