Repository: google/go-github
Pull request #1880 (2021-05-31 02:22:47)

Align Installation Permissions to latest GitHub v3 API reference
This PR is to fix issue #1879 by updating InstallationPermissions struct with new properties included in API Document.

Changes include:
* Update document URL in comment
* Add support for environments, organization_secrets, organization_self_hosted_runners, secrets, secret_scanning_alerts, security_events and workflows
* Align test code with new fields

xun-guo-anzx: Thanks @gmlewis for looking into this. I've run `go generate ./...` command as well as `go test` and `go vet` as described in `CONTRIBUTING.md`. Sorry for missing out one step before submitting the PR.
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1880?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#1880](https://codecov.io/gh/google/go-github/pull/1880?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (a0b4195) into [master](https://codecov.io/gh/google/go-github/commit/8b2866e7e23bd34b7969111879141a84b84409eb?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (8b2866e) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1880/graphs/tree.svg?width=650&height=150&src=pr&token=EgYjGjZlI0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)](https://codecov.io/gh/google/go-github/pull/1880?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)

```diff
@@           Coverage Diff           @@
##           master    #1880   +/-   ##
=======================================
  Coverage   97.65%   97.65%           
=======================================
  Files         105      105           
  Lines        6783     6783           
=======================================
  Hits         6624     6624           
  Misses         86       86           
  Partials       73       73           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1880?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/1880/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL2FwcHMuZ28=) | `95.29% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1880?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1880?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Last update [8b2866e...a0b4195](https://codecov.io/gh/google/go-github/pull/1880?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).

gmlewis: Thank you, @wesleimp !
Merging.

Patch:
diff --git a/github/apps.go b/github/apps.go
index cb0069de..8b850d9e 100644
--- a/github/apps.go
+++ b/github/apps.go
@@ -55,37 +55,44 @@ type InstallationTokenOptions struct {
 // InstallationPermissions lists the repository and organization permissions for an installation.
 //
 // Permission names taken from:
-//   https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/permissions/
-//   https://developer.github.com/enterprise/v3/apps/permissions/
+//   https://docs.github.com/en/enterprise-server@3.0/rest/reference/apps#create-an-installation-access-token-for-an-app
+//   https://docs.github.com/en/rest/reference/apps#create-an-installation-access-token-for-an-app
 type InstallationPermissions struct {
-	Actions                     *string `json:"actions,omitempty"`
-	Administration              *string `json:"administration,omitempty"`
-	Blocking                    *string `json:"blocking,omitempty"`
-	Checks                      *string `json:"checks,omitempty"`
-	Contents                    *string `json:"contents,omitempty"`
-	ContentReferences           *string `json:"content_references,omitempty"`
-	Deployments                 *string `json:"deployments,omitempty"`
-	Emails                      *string `json:"emails,omitempty"`
-	Followers                   *string `json:"followers,omitempty"`
-	Issues                      *string `json:"issues,omitempty"`
-	Metadata                    *string `json:"metadata,omitempty"`
-	Members                     *string `json:"members,omitempty"`
-	OrganizationAdministration  *string `json:"organization_administration,omitempty"`
-	OrganizationHooks           *string `json:"organization_hooks,omitempty"`
-	OrganizationPlan            *string `json:"organization_plan,omitempty"`
-	OrganizationPreReceiveHooks *string `json:"organization_pre_receive_hooks,omitempty"`
-	OrganizationProjects        *string `json:"organization_projects,omitempty"`
-	OrganizationUserBlocking    *string `json:"organization_user_blocking,omitempty"`
-	Packages                    *string `json:"packages,omitempty"`
-	Pages                       *string `json:"pages,omitempty"`
-	PullRequests                *string `json:"pull_requests,omitempty"`
-	RepositoryHooks             *string `json:"repository_hooks,omitempty"`
-	RepositoryProjects          *string `json:"repository_projects,omitempty"`
-	RepositoryPreReceiveHooks   *string `json:"repository_pre_receive_hooks,omitempty"`
-	SingleFile                  *string `json:"single_file,omitempty"`
-	Statuses                    *string `json:"statuses,omitempty"`
-	TeamDiscussions             *string `json:"team_discussions,omitempty"`
-	VulnerabilityAlerts         *string `json:"vulnerability_alerts,omitempty"`
+	Actions                       *string `json:"actions,omitempty"`
+	Administration                *string `json:"administration,omitempty"`
+	Blocking                      *string `json:"blocking,omitempty"`
+	Checks                        *string `json:"checks,omitempty"`
+	Contents                      *string `json:"contents,omitempty"`
+	ContentReferences             *string `json:"content_references,omitempty"`
+	Deployments                   *string `json:"deployments,omitempty"`
+	Emails                        *string `json:"emails,omitempty"`
+	Environments                  *string `json:"environments,omitempty"`
+	Followers                     *string `json:"followers,omitempty"`
+	Issues                        *string `json:"issues,omitempty"`
+	Metadata                      *string `json:"metadata,omitempty"`
+	Members                       *string `json:"members,omitempty"`
+	OrganizationAdministration    *string `json:"organization_administration,omitempty"`
+	OrganizationHooks             *string `json:"organization_hooks,omitempty"`
+	OrganizationPlan              *string `json:"organization_plan,omitempty"`
+	OrganizationPreReceiveHooks   *string `json:"organization_pre_receive_hooks,omitempty"`
+	OrganizationProjects          *string `json:"organization_projects,omitempty"`
+	OrganizationSecrets           *string `json:"organization_secrets,omitempty"`
+	OrganizationSelfHostedRunners *string `json:"organization_self_hosted_runners,omitempty"`
+	OrganizationUserBlocking      *string `json:"organization_user_blocking,omitempty"`
+	Packages                      *string `json:"packages,omitempty"`
+	Pages                         *string `json:"pages,omitempty"`
+	PullRequests                  *string `json:"pull_requests,omitempty"`
+	RepositoryHooks               *string `json:"repository_hooks,omitempty"`
+	RepositoryProjects            *string `json:"repository_projects,omitempty"`
+	RepositoryPreReceiveHooks     *string `json:"repository_pre_receive_hooks,omitempty"`
+	Secrets                       *string `json:"secrets,omitempty"`
+	SecretScanningAlerts          *string `json:"secret_scanning_alerts,omitempty"`
+	SecurityEvents                *string `json:"security_events,omitempty"`
+	SingleFile                    *string `json:"single_file,omitempty"`
+	Statuses                      *string `json:"statuses,omitempty"`
+	TeamDiscussions               *string `json:"team_discussions,omitempty"`
+	VulnerabilityAlerts           *string `json:"vulnerability_alerts,omitempty"`
+	Workflows                     *string `json:"workflows,omitempty"`
 }
 
 // Installation represents a GitHub Apps installation.
diff --git a/github/github-accessors.go b/github/github-accessors.go
index c392d8c9..cb068a69 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -5148,6 +5148,14 @@ func (i *InstallationPermissions) GetEmails() string {
 	return *i.Emails
 }
 
+// GetEnvironments returns the Environments field if it's non-nil, zero value otherwise.
+func (i *InstallationPermissions) GetEnvironments() string {
+	if i == nil || i.Environments == nil {
+		return ""
+	}
+	return *i.Environments
+}
+
 // GetFollowers returns the Followers field if it's non-nil, zero value otherwise.
 func (i *InstallationPermissions) GetFollowers() string {
 	if i == nil || i.Followers == nil {
@@ -5220,6 +5228,22 @@ func (i *InstallationPermissions) GetOrganizationProjects() string {
 	return *i.OrganizationProjects
 }
 
+// GetOrganizationSecrets returns the OrganizationSecrets field if it's non-nil, zero value otherwise.
+func (i *InstallationPermissions) GetOrganizationSecrets() string {
+	if i == nil || i.OrganizationSecrets == nil {
+		return ""
+	}
+	return *i.OrganizationSecrets
+}
+
+// GetOrganizationSelfHostedRunners returns the OrganizationSelfHostedRunners field if it's non-nil, zero value otherwise.
+func (i *InstallationPermissions) GetOrganizationSelfHostedRunners() string {
+	if i == nil || i.OrganizationSelfHostedRunners == nil {
+		return ""
+	}
+	return *i.OrganizationSelfHostedRunners
+}
+
 // GetOrganizationUserBlocking returns the OrganizationUserBlocking field if it's non-nil, zero value otherwise.
 func (i *InstallationPermissions) GetOrganizationUserBlocking() string {
 	if i == nil || i.OrganizationUserBlocking == nil {
@@ -5276,6 +5300,30 @@ func (i *InstallationPermissions) GetRepositoryProjects() string {
 	return *i.RepositoryProjects
 }
 
+// GetSecrets returns the Secrets field if it's non-nil, zero value otherwise.
+func (i *InstallationPermissions) GetSecrets() string {
+	if i == nil || i.Secrets == nil {
+		return ""
+	}
+	return *i.Secrets
+}
+
+// GetSecretScanningAlerts returns the SecretScanningAlerts field if it's non-nil, zero value otherwise.
+func (i *InstallationPermissions) GetSecretScanningAlerts() string {
+	if i == nil || i.SecretScanningAlerts == nil {
+		return ""
+	}
+	return *i.SecretScanningAlerts
+}
+
+// GetSecurityEvents returns the SecurityEvents field if it's non-nil, zero value otherwise.
+func (i *InstallationPermissions) GetSecurityEvents() string {
+	if i == nil || i.SecurityEvents == nil {
+		return ""
+	}
+	return *i.SecurityEvents
+}
+
 // GetSingleFile returns the SingleFile field if it's non-nil, zero value otherwise.
 func (i *InstallationPermissions) GetSingleFile() string {
 	if i == nil || i.SingleFile == nil {
@@ -5308,6 +5356,14 @@ func (i *InstallationPermissions) GetVulnerabilityAlerts() string {
 	return *i.VulnerabilityAlerts
 }
 
+// GetWorkflows returns the Workflows field if it's non-nil, zero value otherwise.
+func (i *InstallationPermissions) GetWorkflows() string {
+	if i == nil || i.Workflows == nil {
+		return ""
+	}
+	return *i.Workflows
+}
+
 // GetAction returns the Action field if it's non-nil, zero value otherwise.
 func (i *InstallationRepositoriesEvent) GetAction() string {
 	if i == nil || i.Action == nil {


Test patch:
diff --git a/github/apps_test.go b/github/apps_test.go
index 73734c65..841fe173 100644
--- a/github/apps_test.go
+++ b/github/apps_test.go
@@ -94,6 +94,7 @@ func TestAppsService_ListInstallations(t *testing.T) {
                                        "contents": "read",
                                        "content_references": "read",
                                        "deployments": "read",
+                                       "environments": "read",
                                        "issues": "write",
                                        "metadata": "read",
                                        "members": "read",
@@ -102,6 +103,8 @@ func TestAppsService_ListInstallations(t *testing.T) {
                                        "organization_plan": "read",
                                        "organization_pre_receive_hooks": "write",
                                        "organization_projects": "read",
+                                       "organization_secrets": "read",
+                                       "organization_self_hosted_runners": "read",
                                        "organization_user_blocking": "write",
                                        "packages": "read",
                                        "pages": "read",
@@ -109,10 +112,14 @@ func TestAppsService_ListInstallations(t *testing.T) {
                                        "repository_hooks": "write",
                                        "repository_projects": "read",
                                        "repository_pre_receive_hooks": "read",
+                                       "secrets": "read",
+                                       "secret_scanning_alerts": "read",
+                                       "security_events": "read",
                                        "single_file": "write",
                                        "statuses": "write",
                                        "team_discussions": "read",
-                                       "vulnerability_alerts": "read"
+                                       "vulnerability_alerts": "read",
+                                       "workflows": "write"
                                    },
                                   "events": [
                                       "push",
@@ -141,31 +148,38 @@ func TestAppsService_ListInstallations(t *testing.T) {
 		SingleFileName:      String("config.yml"),
 		RepositorySelection: String("selected"),
 		Permissions: &InstallationPermissions{
-			Actions:                     String("read"),
-			Administration:              String("read"),
-			Checks:                      String("read"),
-			Contents:                    String("read"),
-			ContentReferences:           String("read"),
-			Deployments:                 String("read"),
-			Issues:                      String("write"),
-			Metadata:                    String("read"),
-			Members:                     String("read"),
-			OrganizationAdministration:  String("write"),
-			OrganizationHooks:           String("write"),
-			OrganizationPlan:            String("read"),
-			OrganizationPreReceiveHooks: String("write"),
-			OrganizationProjects:        String("read"),
-			OrganizationUserBlocking:    String("write"),
-			Packages:                    String("read"),
-			Pages:                       String("read"),
-			PullRequests:                String("write"),
-			RepositoryHooks:             String("write"),
-			RepositoryProjects:          String("read"),
-			RepositoryPreReceiveHooks:   String("read"),
-			SingleFile:                  String("write"),
-			Statuses:                    String("write"),
-			TeamDiscussions:             String("read"),
-			VulnerabilityAlerts:         String("read")},
+			Actions:                       String("read"),
+			Administration:                String("read"),
+			Checks:                        String("read"),
+			Contents:                      String("read"),
+			ContentReferences:             String("read"),
+			Deployments:                   String("read"),
+			Environments:                  String("read"),
+			Issues:                        String("write"),
+			Metadata:                      String("read"),
+			Members:                       String("read"),
+			OrganizationAdministration:    String("write"),
+			OrganizationHooks:             String("write"),
+			OrganizationPlan:              String("read"),
+			OrganizationPreReceiveHooks:   String("write"),
+			OrganizationProjects:          String("read"),
+			OrganizationSecrets:           String("read"),
+			OrganizationSelfHostedRunners: String("read"),
+			OrganizationUserBlocking:      String("write"),
+			Packages:                      String("read"),
+			Pages:                         String("read"),
+			PullRequests:                  String("write"),
+			RepositoryHooks:               String("write"),
+			RepositoryProjects:            String("read"),
+			RepositoryPreReceiveHooks:     String("read"),
+			Secrets:                       String("read"),
+			SecretScanningAlerts:          String("read"),
+			SecurityEvents:                String("read"),
+			SingleFile:                    String("write"),
+			Statuses:                      String("write"),
+			TeamDiscussions:               String("read"),
+			VulnerabilityAlerts:           String("read"),
+			Workflows:                     String("write")},
 		Events:    []string{"push", "pull_request"},
 		CreatedAt: &date,
 		UpdatedAt: &date,
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 7dfb0011..5695e3fb 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -6079,6 +6079,16 @@ func TestInstallationPermissions_GetEmails(tt *testing.T) {
 	i.GetEmails()
 }
 
+func TestInstallationPermissions_GetEnvironments(tt *testing.T) {
+	var zeroValue string
+	i := &InstallationPermissions{Environments: &zeroValue}
+	i.GetEnvironments()
+	i = &InstallationPermissions{}
+	i.GetEnvironments()
+	i = nil
+	i.GetEnvironments()
+}
+
 func TestInstallationPermissions_GetFollowers(tt *testing.T) {
 	var zeroValue string
 	i := &InstallationPermissions{Followers: &zeroValue}
@@ -6169,6 +6179,26 @@ func TestInstallationPermissions_GetOrganizationProjects(tt *testing.T) {
 	i.GetOrganizationProjects()
 }
 
+func TestInstallationPermissions_GetOrganizationSecrets(tt *testing.T) {
+	var zeroValue string
+	i := &InstallationPermissions{OrganizationSecrets: &zeroValue}
+	i.GetOrganizationSecrets()
+	i = &InstallationPermissions{}
+	i.GetOrganizationSecrets()
+	i = nil
+	i.GetOrganizationSecrets()
+}
+
+func TestInstallationPermissions_GetOrganizationSelfHostedRunners(tt *testing.T) {
+	var zeroValue string
+	i := &InstallationPermissions{OrganizationSelfHostedRunners: &zeroValue}
+	i.GetOrganizationSelfHostedRunners()
+	i = &InstallationPermissions{}
+	i.GetOrganizationSelfHostedRunners()
+	i = nil
+	i.GetOrganizationSelfHostedRunners()
+}
+
 func TestInstallationPermissions_GetOrganizationUserBlocking(tt *testing.T) {
 	var zeroValue string
 	i := &InstallationPermissions{OrganizationUserBlocking: &zeroValue}
@@ -6239,6 +6269,36 @@ func TestInstallationPermissions_GetRepositoryProjects(tt *testing.T) {
 	i.GetRepositoryProjects()
 }
 
+func TestInstallationPermissions_GetSecrets(tt *testing.T) {
+	var zeroValue string
+	i := &InstallationPermissions{Secrets: &zeroValue}
+	i.GetSecrets()
+	i = &InstallationPermissions{}
+	i.GetSecrets()
+	i = nil
+	i.GetSecrets()
+}
+
+func TestInstallationPermissions_GetSecretScanningAlerts(tt *testing.T) {
+	var zeroValue string
+	i := &InstallationPermissions{SecretScanningAlerts: &zeroValue}
+	i.GetSecretScanningAlerts()
+	i = &InstallationPermissions{}
+	i.GetSecretScanningAlerts()
+	i = nil
+	i.GetSecretScanningAlerts()
+}
+
+func TestInstallationPermissions_GetSecurityEvents(tt *testing.T) {
+	var zeroValue string
+	i := &InstallationPermissions{SecurityEvents: &zeroValue}
+	i.GetSecurityEvents()
+	i = &InstallationPermissions{}
+	i.GetSecurityEvents()
+	i = nil
+	i.GetSecurityEvents()
+}
+
 func TestInstallationPermissions_GetSingleFile(tt *testing.T) {
 	var zeroValue string
 	i := &InstallationPermissions{SingleFile: &zeroValue}
@@ -6279,6 +6339,16 @@ func TestInstallationPermissions_GetVulnerabilityAlerts(tt *testing.T) {
 	i.GetVulnerabilityAlerts()
 }
 
+func TestInstallationPermissions_GetWorkflows(tt *testing.T) {
+	var zeroValue string
+	i := &InstallationPermissions{Workflows: &zeroValue}
+	i.GetWorkflows()
+	i = &InstallationPermissions{}
+	i.GetWorkflows()
+	i = nil
+	i.GetWorkflows()
+}
+
 func TestInstallationRepositoriesEvent_GetAction(tt *testing.T) {
 	var zeroValue string
 	i := &InstallationRepositoriesEvent{Action: &zeroValue}