Repository: google/go-github (go)

Issue:
Return TotalCount in ListRepos in AppsService
`ListRepos` currently only returns the list of repositories from github's response but not the total_count ([Link](https://docs.github.com/en/rest/reference/apps#list-repositories-accessible-to-the-app-installation)). This total_count is different from just the length of the list of repositories returned if the number of repositories in the installation is greater than the per_page pagination limit set in the request. Is it possible to add it for ListRepos to return? 

Pull request:
Change ListRepos and ListUserRepos to return new ListRepositories struct with count
- Fixes #1791
- Modified Tests in `apps_installations_test.go`

Patch:
diff --git a/github/apps_installation.go b/github/apps_installation.go
index 3da39131..b4ac5eef 100644
--- a/github/apps_installation.go
+++ b/github/apps_installation.go
@@ -10,10 +10,16 @@ import (
 	"fmt"
 )
 
+// ListRepositories represents the response from the list repos endpoints.
+type ListRepositories struct {
+	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
@@ -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 {
@@ -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.
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 392065c7..b9160192 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -5988,6 +5988,14 @@ func (l *ListCollaboratorOptions) GetAffiliation() string {
 	return *l.Affiliation
 }
 
+// GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise.
+func (l *ListRepositories) GetTotalCount() int {
+	if l == nil || l.TotalCount == nil {
+		return 0
+	}
+	return *l.TotalCount
+}
+
 // GetEffectiveDate returns the EffectiveDate field if it's non-nil, zero value otherwise.
 func (m *MarketplacePendingChange) GetEffectiveDate() Timestamp {
 	if m == nil || m.EffectiveDate == nil {


Test patch:
diff --git a/github/apps_installation_test.go b/github/apps_installation_test.go
index 5c2a8b6b..a73498c6 100644
--- a/github/apps_installation_test.go
+++ b/github/apps_installation_test.go
@@ -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}
@@ -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)
 	}
@@ -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}
@@ -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)
 	}
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 301c6225..e7a22dca 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -7012,6 +7012,16 @@ func TestListCollaboratorOptions_GetAffiliation(tt *testing.T) {
 	l.GetAffiliation()
 }
 
+func TestListRepositories_GetTotalCount(tt *testing.T) {
+	var zeroValue int
+	l := &ListRepositories{TotalCount: &zeroValue}
+	l.GetTotalCount()
+	l = &ListRepositories{}
+	l.GetTotalCount()
+	l = nil
+	l.GetTotalCount()
+}
+
 func TestMarketplacePendingChange_GetEffectiveDate(tt *testing.T) {
 	var zeroValue Timestamp
 	m := &MarketplacePendingChange{EffectiveDate: &zeroValue}