From a9dc9b192583bbda410e7406350c9725af0d875a Mon Sep 17 00:00:00 2001 From: James Maguire Date: Tue, 28 Mar 2023 10:13:26 +0200 Subject: [PATCH 1/4] Add CanAdminsBypass to Environment --- github/repos_environments.go | 1 + github/repos_environments_test.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/github/repos_environments.go b/github/repos_environments.go index 2e85fdf99c0..81385068769 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"` + CanAdminBypass *bool `json:"can_admin_bypass"` ProtectionRules []*ProtectionRule `json:"protection_rules,omitempty"` } diff --git a/github/repos_environments_test.go b/github/repos_environments_test.go index 0b27da933d7..1aebb1daaef 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_admin_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)}, CanAdminBypass: Bool(false)} if !cmp.Equal(release, want) { t.Errorf("Repositories.GetEnvironment returned %+v, want %+v", release, want) } From cc68e20269063454af44f6f39396aab4ce605df9 Mon Sep 17 00:00:00 2001 From: James Maguire Date: Tue, 28 Mar 2023 10:17:10 +0200 Subject: [PATCH 2/4] fix typo --- github/repos_environments.go | 2 +- github/repos_environments_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/github/repos_environments.go b/github/repos_environments.go index 81385068769..10075d05d0c 100644 --- a/github/repos_environments.go +++ b/github/repos_environments.go @@ -28,7 +28,7 @@ type Environment struct { HTMLURL *string `json:"html_url,omitempty"` CreatedAt *Timestamp `json:"created_at,omitempty"` UpdatedAt *Timestamp `json:"updated_at,omitempty"` - CanAdminBypass *bool `json:"can_admin_bypass"` + CanAdminsBypass *bool `json:"can_admins_bypass"` ProtectionRules []*ProtectionRule `json:"protection_rules,omitempty"` } diff --git a/github/repos_environments_test.go b/github/repos_environments_test.go index 1aebb1daaef..a688b221fc2 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}, "can_admin_bypass": 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)}, CanAdminBypass: 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) } From 721c65868400a9b5606f8aeb839d053695118a2b Mon Sep 17 00:00:00 2001 From: James Maguire Date: Tue, 28 Mar 2023 10:40:23 +0200 Subject: [PATCH 3/4] add omitempty --- github/repos_environments.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/repos_environments.go b/github/repos_environments.go index 10075d05d0c..7f01be6277f 100644 --- a/github/repos_environments.go +++ b/github/repos_environments.go @@ -28,7 +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"` + CanAdminsBypass *bool `json:"can_admins_bypass,omitempty"` ProtectionRules []*ProtectionRule `json:"protection_rules,omitempty"` } From a90b2eb91d58f50e3cc75c6b88fa588ded73d8fa Mon Sep 17 00:00:00 2001 From: James Maguire Date: Tue, 28 Mar 2023 15:12:51 +0200 Subject: [PATCH 4/4] run `go generate` --- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/github/github-accessors.go b/github/github-accessors.go index 3d42907b96c..9c435048aec 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/github-accessors_test.go b/github/github-accessors_test.go index 20ba7425d7a..5091cc46c90 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}