Repository: google/go-github
Pull request #2721 (2023-03-28 08:14:39)

Add `CanAdminsBypass` to Environment
Fixes: https://github.com/google/go-github/issues/2722

codecov[bot]: ## [Codecov](https://codecov.io/gh/google/go-github/pull/2721?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> :exclamation: No coverage uploaded for pull request base (`master@795005a`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#section-missing-base-commit).
> The diff coverage is `n/a`.

```diff
@@            Coverage Diff            @@
##             master    #2721   +/-   ##
=========================================
  Coverage          ?   98.05%           
=========================================
  Files             ?      131           
  Lines             ?    11459           
  Branches          ?        0           
=========================================
  Hits              ?    11236           
  Misses            ?      152           
  Partials          ?       71           
```


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

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)


Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 3d42907b..9c435048 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -5590,6 +5590,14 @@ func (e *EnterpriseSecurityAnalysisSettings) GetSecretScanningPushProtectionEnab
 	return *e.SecretScanningPushProtectionEnabledForNewRepositories
 }
 
+// GetCanAdminsBypass returns the CanAdminsBypass field if it's non-nil, zero value otherwise.
+func (e *Environment) GetCanAdminsBypass() bool {
+	if e == nil || e.CanAdminsBypass == nil {
+		return false
+	}
+	return *e.CanAdminsBypass
+}
+
 // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
 func (e *Environment) GetCreatedAt() Timestamp {
 	if e == nil || e.CreatedAt == nil {
diff --git a/github/repos_environments.go b/github/repos_environments.go
index 2e85fdf9..7f01be62 100644
--- a/github/repos_environments.go
+++ b/github/repos_environments.go
@@ -28,6 +28,7 @@ type Environment struct {
 	HTMLURL         *string           `json:"html_url,omitempty"`
 	CreatedAt       *Timestamp        `json:"created_at,omitempty"`
 	UpdatedAt       *Timestamp        `json:"updated_at,omitempty"`
+	CanAdminsBypass *bool             `json:"can_admins_bypass,omitempty"`
 	ProtectionRules []*ProtectionRule `json:"protection_rules,omitempty"`
 }
 


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 20ba7425..5091cc46 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -6541,6 +6541,16 @@ func TestEnterpriseSecurityAnalysisSettings_GetSecretScanningPushProtectionEnabl
 	e.GetSecretScanningPushProtectionEnabledForNewRepositories()
 }
 
+func TestEnvironment_GetCanAdminsBypass(tt *testing.T) {
+	var zeroValue bool
+	e := &Environment{CanAdminsBypass: &zeroValue}
+	e.GetCanAdminsBypass()
+	e = &Environment{}
+	e.GetCanAdminsBypass()
+	e = nil
+	e.GetCanAdminsBypass()
+}
+
 func TestEnvironment_GetCreatedAt(tt *testing.T) {
 	var zeroValue Timestamp
 	e := &Environment{CreatedAt: &zeroValue}
diff --git a/github/repos_environments_test.go b/github/repos_environments_test.go
index 0b27da93..a688b221 100644
--- a/github/repos_environments_test.go
+++ b/github/repos_environments_test.go
@@ -145,7 +145,7 @@ func TestRepositoriesService_GetEnvironment(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/environments/e", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
-		fmt.Fprint(w, `{"id": 1,"name": "staging", "deployment_branch_policy": {"protected_branches": true,	"custom_branch_policies": false}}`)
+		fmt.Fprint(w, `{"id": 1,"name": "staging", "deployment_branch_policy": {"protected_branches": true,	"custom_branch_policies": false}, "can_admins_bypass": false}`)
 	})
 
 	ctx := context.Background()
@@ -154,7 +154,7 @@ func TestRepositoriesService_GetEnvironment(t *testing.T) {
 		t.Errorf("Repositories.GetEnvironment returned error: %v\n%v", err, resp.Body)
 	}
 
-	want := &Environment{ID: Int64(1), Name: String("staging"), DeploymentBranchPolicy: &BranchPolicy{ProtectedBranches: Bool(true), CustomBranchPolicies: Bool(false)}}
+	want := &Environment{ID: Int64(1), Name: String("staging"), DeploymentBranchPolicy: &BranchPolicy{ProtectedBranches: Bool(true), CustomBranchPolicies: Bool(false)}, CanAdminsBypass: Bool(false)}
 	if !cmp.Equal(release, want) {
 		t.Errorf("Repositories.GetEnvironment returned %+v, want %+v", release, want)
 	}