-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add app hook deliveries API #2226
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a75d33
Update gitignore for vim temp files.
pierce-m 41f9708
Update gitignore for vim temp files.
pierce-m 9f3428f
Add support for listing app hook deliveries.
pierce-m 089e2ad
Add redelivery functionality.
pierce-m 729ca6b
Add support for getting an app webhook delivery.
pierce-m 4f4f714
Revert adding delivery struct.
pierce-m cca80b1
Fix wrong method.
pierce-m ae3ffa2
Update github/apps_hooks_deliveries.go
pierce-m 01fb5eb
Update github/apps_hooks_deliveries.go
pierce-m 7beecfa
Update github/apps_hooks_deliveries.go
pierce-m 2aa17ba
Update github/apps_hooks_deliveries_test.go
pierce-m 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
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 |
---|---|---|
|
@@ -5,4 +5,6 @@ coverage.out | |
.idea/ | ||
vendor/ | ||
.DS_Store | ||
.vscode | ||
.vscode | ||
# vim temp files | ||
*.swp |
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,72 @@ | ||
// 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" | ||
) | ||
|
||
// ListHookDeliveries lists deliveries of an App webhook. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/reference/apps#list-deliveries-for-an-app-webhook | ||
func (s *AppsService) ListHookDeliveries(ctx context.Context, opts *ListCursorOptions) ([]*HookDelivery, *Response, error) { | ||
u, err := addOptions("app/hook/deliveries", 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 the App webhook delivery with the specified ID. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/reference/apps#get-a-delivery-for-an-app-webhook | ||
func (s *AppsService) GetHookDelivery(ctx context.Context, deliveryID int64) (*HookDelivery, *Response, error) { | ||
u := fmt.Sprintf("app/hook/deliveries/%v", deliveryID) | ||
req, err := s.client.NewRequest("GET", 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 | ||
} | ||
|
||
// RedeliverHookDelivery redelivers a delivery for an App webhook. | ||
// | ||
// GitHub API docs: https://docs.github.com/en/rest/reference/apps#redeliver-a-delivery-for-an-app-webhook | ||
func (s *AppsService) RedeliverHookDelivery(ctx context.Context, deliveryID int64) (*HookDelivery, *Response, error) { | ||
u := fmt.Sprintf("app/hook/deliveries/%v/attempts", 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 | ||
} |
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,119 @@ | ||
// 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 TestAppsService_ListHookDeliveries(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/app/hook/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}]`) | ||
}) | ||
|
||
opts := &ListCursorOptions{Cursor: "v1_12077215967"} | ||
|
||
ctx := context.Background() | ||
|
||
deliveries, _, err := client.Apps.ListHookDeliveries(ctx, opts) | ||
if err != nil { | ||
t.Errorf("Apps.ListHookDeliveries returned error: %v", err) | ||
} | ||
|
||
want := []*HookDelivery{{ID: Int64(1)}, {ID: Int64(2)}} | ||
if d := cmp.Diff(deliveries, want); d != "" { | ||
t.Errorf("Apps.ListHooks want (-), got (+):\n%s", d) | ||
} | ||
|
||
const methodName = "ListHookDeliveries" | ||
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
got, resp, err := client.Apps.ListHookDeliveries(ctx, opts) | ||
if got != nil { | ||
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) | ||
} | ||
return resp, err | ||
}) | ||
} | ||
|
||
func TestAppsService_GetHookDelivery(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/app/hook/deliveries/1", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
fmt.Fprint(w, `{"id":1}`) | ||
}) | ||
|
||
ctx := context.Background() | ||
hook, _, err := client.Apps.GetHookDelivery(ctx, 1) | ||
if err != nil { | ||
t.Errorf("Apps.GetHookDelivery returned error: %v", err) | ||
} | ||
|
||
want := &HookDelivery{ID: Int64(1)} | ||
if !cmp.Equal(hook, want) { | ||
t.Errorf("Apps.GetHookDelivery returned %+v, want %+v", hook, want) | ||
} | ||
|
||
const methodName = "GetHookDelivery" | ||
testBadOptions(t, methodName, func() (err error) { | ||
_, _, err = client.Apps.GetHookDelivery(ctx, -1) | ||
return err | ||
}) | ||
|
||
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
got, resp, err := client.Apps.GetHookDelivery(ctx, 1) | ||
if got != nil { | ||
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) | ||
} | ||
return resp, err | ||
}) | ||
} | ||
|
||
func TestAppsService_RedeliverHookDelivery(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc("/app/hook/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.Apps.RedeliverHookDelivery(ctx, 1) | ||
if err != nil { | ||
t.Errorf("Apps.RedeliverHookDelivery returned error: %v", err) | ||
} | ||
|
||
want := &HookDelivery{ID: Int64(1)} | ||
if !cmp.Equal(hook, want) { | ||
t.Errorf("Apps.RedeliverHookDelivery returned %+v, want %+v", hook, want) | ||
} | ||
|
||
const methodName = "RedeliverHookDelivery" | ||
testBadOptions(t, methodName, func() (err error) { | ||
_, _, err = client.Apps.RedeliverHookDelivery(ctx, -1) | ||
return err | ||
}) | ||
|
||
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
got, resp, err := client.Apps.RedeliverHookDelivery(ctx, 1) | ||
if got != nil { | ||
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) | ||
} | ||
return resp, 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.