diff --git a/github/github-accessors.go b/github/github-accessors.go index 9c435048ae..1a9f32ef05 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4022,6 +4022,14 @@ func (c *CreateRunnerGroupRequest) GetVisibility() string { return *c.Visibility } +// GetCanAdminsBypass returns the CanAdminsBypass field if it's non-nil, zero value otherwise. +func (c *CreateUpdateEnvironment) GetCanAdminsBypass() bool { + if c == nil || c.CanAdminsBypass == nil { + return false + } + return *c.CanAdminsBypass +} + // GetDeploymentBranchPolicy returns the DeploymentBranchPolicy field. func (c *CreateUpdateEnvironment) GetDeploymentBranchPolicy() *BranchPolicy { if c == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 5091cc46c9..039c3e17b0 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -4725,6 +4725,16 @@ func TestCreateRunnerGroupRequest_GetVisibility(tt *testing.T) { c.GetVisibility() } +func TestCreateUpdateEnvironment_GetCanAdminsBypass(tt *testing.T) { + var zeroValue bool + c := &CreateUpdateEnvironment{CanAdminsBypass: &zeroValue} + c.GetCanAdminsBypass() + c = &CreateUpdateEnvironment{} + c.GetCanAdminsBypass() + c = nil + c.GetCanAdminsBypass() +} + func TestCreateUpdateEnvironment_GetDeploymentBranchPolicy(tt *testing.T) { c := &CreateUpdateEnvironment{} c.GetDeploymentBranchPolicy() diff --git a/github/repos_environments.go b/github/repos_environments.go index 7f01be6277..2399a42c74 100644 --- a/github/repos_environments.go +++ b/github/repos_environments.go @@ -148,11 +148,15 @@ func (s *RepositoriesService) GetEnvironment(ctx context.Context, owner, repo, n // MarshalJSON implements the json.Marshaler interface. // As the only way to clear a WaitTimer is to set it to 0, a missing WaitTimer object should default to 0, not null. +// As the default value for CanAdminsBypass is true, a nil value here marshals to true. func (c *CreateUpdateEnvironment) MarshalJSON() ([]byte, error) { type Alias CreateUpdateEnvironment if c.WaitTimer == nil { c.WaitTimer = Int(0) } + if c.CanAdminsBypass == nil { + c.CanAdminsBypass = Bool(true) + } return json.Marshal(&struct { *Alias }{ @@ -167,6 +171,7 @@ func (c *CreateUpdateEnvironment) MarshalJSON() ([]byte, error) { type CreateUpdateEnvironment struct { WaitTimer *int `json:"wait_timer"` Reviewers []*EnvReviewers `json:"reviewers"` + CanAdminsBypass *bool `json:"can_admins_bypass"` DeploymentBranchPolicy *BranchPolicy `json:"deployment_branch_policy"` } diff --git a/github/repos_environments_test.go b/github/repos_environments_test.go index a688b221fc..0f93d29088 100644 --- a/github/repos_environments_test.go +++ b/github/repos_environments_test.go @@ -93,7 +93,7 @@ func TestCreateUpdateEnvironment_MarshalJSON(t *testing.T) { t.Errorf("MarshalJSON: %v", err) } - want := `{"wait_timer":0,"reviewers":null,"deployment_branch_policy":null}` + want := `{"wait_timer":0,"reviewers":null,"can_admins_bypass":true,"deployment_branch_policy":null}` if string(got) != want { t.Errorf("MarshalJSON = %s, want %v", got, want) } @@ -187,7 +187,7 @@ func TestRepositoriesService_CreateEnvironment(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "PUT") - want := &CreateUpdateEnvironment{WaitTimer: Int(30)} + want := &CreateUpdateEnvironment{WaitTimer: Int(30), CanAdminsBypass: Bool(true)} if !cmp.Equal(v, want) { t.Errorf("Request body = %+v, want %+v", v, want) }