Skip to content
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

Add List Installation Requests API #2947

Merged
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
32 changes: 32 additions & 0 deletions github/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@
Workflows *string `json:"workflows,omitempty"`
}

// InstallationRequest represents a pending GitHub App installation request.
type InstallationRequest struct {
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Account *User `json:"account,omitempty"`
Requester *User `json:"requester,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
}

// Installation represents a GitHub Apps installation.
type Installation struct {
ID *int64 `json:"id,omitempty"`
Expand Down Expand Up @@ -175,6 +184,29 @@
return app, resp, nil
}

// ListInstallationRequests lists the pending installation requests that the current GitHub App has.
//
// GitHub API docs: https://docs.github.com/en/rest/apps/apps#list-installation-requests-for-the-authenticated-app
func (s *AppsService) ListInstallationRequests(ctx context.Context, opts *ListOptions) ([]*InstallationRequest, *Response, error) {
u, err := addOptions("app/installation-requests", opts)
if err != nil {
return nil, nil, err
}

Check warning on line 194 in github/apps.go

View check run for this annotation

Codecov / codecov/patch

github/apps.go#L193-L194

Added lines #L193 - L194 were not covered by tests

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

var i []*InstallationRequest
resp, err := s.client.Do(ctx, req, &i)
if err != nil {
return nil, resp, err
}

return i, resp, nil
}

// ListInstallations lists the installations that the current GitHub App has.
//
// GitHub API docs: https://docs.github.com/en/rest/apps/apps#list-installations-for-the-authenticated-app
Expand Down
47 changes: 47 additions & 0 deletions github/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,53 @@ func TestAppsService_Get_specifiedApp(t *testing.T) {
}
}

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

mux.HandleFunc("/app/installation-requests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"page": "1",
"per_page": "2",
})
fmt.Fprint(w, `[{
"id": 1,
"account": { "id": 2 },
"requester": { "id": 3 },
"created_at": "2018-01-01T00:00:00Z"
}]`,
)
})

opt := &ListOptions{Page: 1, PerPage: 2}
ctx := context.Background()
installationRequests, _, err := client.Apps.ListInstallationRequests(ctx, opt)
if err != nil {
t.Errorf("Apps.ListInstallations returned error: %v", err)
}

date := Timestamp{Time: time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}
want := []*InstallationRequest{{
ID: Int64(1),
Account: &User{ID: Int64(2)},
Requester: &User{ID: Int64(3)},
CreatedAt: &date,
}}
if !cmp.Equal(installationRequests, want) {
t.Errorf("Apps.ListInstallationRequests returned %+v, want %+v", installationRequests, want)
}

const methodName = "ListInstallationRequests"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Apps.ListInstallationRequests(ctx, opt)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestAppsService_ListInstallations(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down
40 changes: 40 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading