Skip to content
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
23 changes: 13 additions & 10 deletions github/apps_installation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ import (
"fmt"
)

// ListRepositories represents the response from the list repos endpoints.
type ListRepositories struct {
Comment thread
gmlewis marked this conversation as resolved.
TotalCount *int `json:"total_count,omitempty"`
Repositories []*Repository `json:"repositories"`
}

// ListRepos lists the repositories that are accessible to the authenticated installation.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-repositories-accessible-to-the-app-installation
func (s *AppsService) ListRepos(ctx context.Context, opts *ListOptions) ([]*Repository, *Response, error) {
func (s *AppsService) ListRepos(ctx context.Context, opts *ListOptions) (*ListRepositories, *Response, error) {
u, err := addOptions("installation/repositories", opts)
if err != nil {
return nil, nil, err
Expand All @@ -24,22 +30,21 @@ func (s *AppsService) ListRepos(ctx context.Context, opts *ListOptions) ([]*Repo
return nil, nil, err
}

var r struct {
Repositories []*Repository `json:"repositories"`
}
var r *ListRepositories

resp, err := s.client.Do(ctx, req, &r)
if err != nil {
return nil, resp, err
}

return r.Repositories, resp, nil
return r, resp, nil
}

// ListUserRepos lists repositories that are accessible
// to the authenticated user for an installation.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-repositories-accessible-to-the-user-access-token
func (s *AppsService) ListUserRepos(ctx context.Context, id int64, opts *ListOptions) ([]*Repository, *Response, error) {
func (s *AppsService) ListUserRepos(ctx context.Context, id int64, opts *ListOptions) (*ListRepositories, *Response, error) {
u := fmt.Sprintf("user/installations/%v/repositories", id)
u, err := addOptions(u, opts)
if err != nil {
Expand All @@ -51,15 +56,13 @@ func (s *AppsService) ListUserRepos(ctx context.Context, id int64, opts *ListOpt
return nil, nil, err
}

var r struct {
Repositories []*Repository `json:"repositories"`
}
var r *ListRepositories
resp, err := s.client.Do(ctx, req, &r)
if err != nil {
return nil, resp, err
}

return r.Repositories, resp, nil
return r, resp, nil
}

// AddRepository adds a single repository to an installation.
Expand Down
8 changes: 4 additions & 4 deletions github/apps_installation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAppsService_ListRepos(t *testing.T) {
"page": "1",
"per_page": "2",
})
fmt.Fprint(w, `{"repositories": [{"id":1}]}`)
fmt.Fprint(w, `{"total_count": 1,"repositories": [{"id": 1}]}`)
})

opt := &ListOptions{Page: 1, PerPage: 2}
Expand All @@ -33,7 +33,7 @@ func TestAppsService_ListRepos(t *testing.T) {
t.Errorf("Apps.ListRepos returned error: %v", err)
}

want := []*Repository{{ID: Int64(1)}}
want := &ListRepositories{TotalCount: Int(1), Repositories: []*Repository{{ID: Int64(1)}}}
if !reflect.DeepEqual(repositories, want) {
t.Errorf("Apps.ListRepos returned %+v, want %+v", repositories, want)
}
Expand All @@ -58,7 +58,7 @@ func TestAppsService_ListUserRepos(t *testing.T) {
"page": "1",
"per_page": "2",
})
fmt.Fprint(w, `{"repositories": [{"id":1}]}`)
fmt.Fprint(w, `{"total_count":1,"repositories": [{"id":1}]}`)
})

opt := &ListOptions{Page: 1, PerPage: 2}
Expand All @@ -68,7 +68,7 @@ func TestAppsService_ListUserRepos(t *testing.T) {
t.Errorf("Apps.ListUserRepos returned error: %v", err)
}

want := []*Repository{{ID: Int64(1)}}
want := &ListRepositories{TotalCount: Int(1), Repositories: []*Repository{{ID: Int64(1)}}}
if !reflect.DeepEqual(repositories, want) {
t.Errorf("Apps.ListUserRepos returned %+v, want %+v", repositories, want)
}
Expand Down
8 changes: 8 additions & 0 deletions github/github-accessors.go

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

10 changes: 10 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.