Repository: google/go-github
Pull request #2765 (2023-04-19 11:59:35)

Add InstallationsCount to App
It's not in the official github documentation yet but exposed to the API.

```
% curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer $T" https://api.github.com/app|grep installations_count
  "installations_count": 3
  ```

gmlewis: > @gmlewis apologies for the noise, i kinda messed my pr!

No problem, @chmouel !  There's no rush... please feel free to take as long as you wish.
chmouel: I am not really sure why it fails on CI

```
% go clean -testcache
% go generate github.com/google/go-github/..
% go test github.com/google/go-github/...
?   	github.com/google/go-github/v51/test/fields	[no test files]
?   	github.com/google/go-github/v51/test/integration	[no test files]
ok  	github.com/google/go-github/v51/github	0.898s
```

is it because i am using go 1.20 ?
chmouel: ah it works better with `go generate -x` should we maybe updated CONTRIBUTING.md ?
codecov[bot]: ## [Codecov](https://codecov.io/gh/google/go-github/pull/2765?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2765](https://codecov.io/gh/google/go-github/pull/2765?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (9d5f093) into [master](https://codecov.io/gh/google/go-github/commit/693ddffe1aa1033b6de421130ac3a0423f27c0de?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (693ddff) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2765   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files         132      132           
  Lines       11638    11638           
=======================================
  Hits        11412    11412           
  Misses        154      154           
  Partials       72       72           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2765?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/apps.go](https://codecov.io/gh/google/go-github/pull/2765?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2FwcHMuZ28=) | `95.16% <ø> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)

gmlewis: > ah it works better with `go generate -x` should we maybe update CONTRIBUTING.md ?

Feel free to clarify if you think that would be helpful.
chmouel: > Feel free to clarify if you think that would be helpful.

I think it was not just my day today, and just was too quick without thinking much, apologies again for the nose, will be careful next time when contributing.

(I missed a dot to `go generate github.com/google/go-github/..` 🤦🏻 )

Patch:
diff --git a/github/apps.go b/github/apps.go
index e1d9aada..ab83d59a 100644
--- a/github/apps.go
+++ b/github/apps.go
@@ -18,18 +18,19 @@ type AppsService service
 
 // App represents a GitHub App.
 type App struct {
-	ID          *int64                   `json:"id,omitempty"`
-	Slug        *string                  `json:"slug,omitempty"`
-	NodeID      *string                  `json:"node_id,omitempty"`
-	Owner       *User                    `json:"owner,omitempty"`
-	Name        *string                  `json:"name,omitempty"`
-	Description *string                  `json:"description,omitempty"`
-	ExternalURL *string                  `json:"external_url,omitempty"`
-	HTMLURL     *string                  `json:"html_url,omitempty"`
-	CreatedAt   *Timestamp               `json:"created_at,omitempty"`
-	UpdatedAt   *Timestamp               `json:"updated_at,omitempty"`
-	Permissions *InstallationPermissions `json:"permissions,omitempty"`
-	Events      []string                 `json:"events,omitempty"`
+	ID                 *int64                   `json:"id,omitempty"`
+	Slug               *string                  `json:"slug,omitempty"`
+	NodeID             *string                  `json:"node_id,omitempty"`
+	Owner              *User                    `json:"owner,omitempty"`
+	Name               *string                  `json:"name,omitempty"`
+	Description        *string                  `json:"description,omitempty"`
+	ExternalURL        *string                  `json:"external_url,omitempty"`
+	HTMLURL            *string                  `json:"html_url,omitempty"`
+	CreatedAt          *Timestamp               `json:"created_at,omitempty"`
+	UpdatedAt          *Timestamp               `json:"updated_at,omitempty"`
+	Permissions        *InstallationPermissions `json:"permissions,omitempty"`
+	Events             []string                 `json:"events,omitempty"`
+	InstallationsCount *int                     `json:"installations_count,omitempty"`
 }
 
 // InstallationToken represents an installation token.
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 76357945..2f40756f 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -678,6 +678,14 @@ func (a *App) GetID() int64 {
 	return *a.ID
 }
 
+// GetInstallationsCount returns the InstallationsCount field if it's non-nil, zero value otherwise.
+func (a *App) GetInstallationsCount() int {
+	if a == nil || a.InstallationsCount == nil {
+		return 0
+	}
+	return *a.InstallationsCount
+}
+
 // GetName returns the Name field if it's non-nil, zero value otherwise.
 func (a *App) GetName() string {
 	if a == nil || a.Name == nil {


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index ad885a4c..0a5d3a6e 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -785,6 +785,16 @@ func TestApp_GetID(tt *testing.T) {
 	a.GetID()
 }
 
+func TestApp_GetInstallationsCount(tt *testing.T) {
+	var zeroValue int
+	a := &App{InstallationsCount: &zeroValue}
+	a.GetInstallationsCount()
+	a = &App{}
+	a.GetInstallationsCount()
+	a = nil
+	a.GetInstallationsCount()
+}
+
 func TestApp_GetName(tt *testing.T) {
 	var zeroValue string
 	a := &App{Name: &zeroValue}