Skip to content

Commit 7fea45a

Browse files
committed
align PUT functionality
1 parent 6af0999 commit 7fea45a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

github/repos_environments.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,15 @@ func (s *RepositoriesService) GetEnvironment(ctx context.Context, owner, repo, n
148148

149149
// MarshalJSON implements the json.Marshaler interface.
150150
// As the only way to clear a WaitTimer is to set it to 0, a missing WaitTimer object should default to 0, not null.
151+
// As the default value for CanAdminBypass is true, a nil value here marshals to true.
151152
func (c *CreateUpdateEnvironment) MarshalJSON() ([]byte, error) {
152153
type Alias CreateUpdateEnvironment
153154
if c.WaitTimer == nil {
154155
c.WaitTimer = Int(0)
155156
}
157+
if c.CanAdminsBypass == nil {
158+
c.CanAdminsBypass = Bool(true)
159+
}
156160
return json.Marshal(&struct {
157161
*Alias
158162
}{
@@ -163,13 +167,11 @@ func (c *CreateUpdateEnvironment) MarshalJSON() ([]byte, error) {
163167
// CreateUpdateEnvironment represents the fields required for the create/update operation
164168
// following the Create/Update release example.
165169
// See https://github.com/google/go-github/issues/992 for more information.
166-
// Removed omitempty here for for reviewers and deployment_branch_policy as the API expects null values to clear them.
167-
// WaitTimer is set to 0 by the marshaller when empty.
168-
// The API does not accept a null value for can_admins_bypass, so an empty value here is omitted.
170+
// Removed omitempty here as the API expects null values for reviewers and deployment_branch_policy to clear them.
169171
type CreateUpdateEnvironment struct {
170172
WaitTimer *int `json:"wait_timer"`
171173
Reviewers []*EnvReviewers `json:"reviewers"`
172-
CanAdminsBypass *bool `json:"can_admins_bypass,omitempty"`
174+
CanAdminsBypass *bool `json:"can_admins_bypass"`
173175
DeploymentBranchPolicy *BranchPolicy `json:"deployment_branch_policy"`
174176
}
175177

github/repos_environments_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestCreateUpdateEnvironment_MarshalJSON(t *testing.T) {
9393
t.Errorf("MarshalJSON: %v", err)
9494
}
9595

96-
want := `{"wait_timer":0,"reviewers":null,"deployment_branch_policy":null}`
96+
want := `{"wait_timer":0,"reviewers":null,"can_admins_bypass":true,"deployment_branch_policy":null}`
9797
if string(got) != want {
9898
t.Errorf("MarshalJSON = %s, want %v", got, want)
9999
}
@@ -187,7 +187,7 @@ func TestRepositoriesService_CreateEnvironment(t *testing.T) {
187187
json.NewDecoder(r.Body).Decode(v)
188188

189189
testMethod(t, r, "PUT")
190-
want := &CreateUpdateEnvironment{WaitTimer: Int(30)}
190+
want := &CreateUpdateEnvironment{WaitTimer: Int(30), CanAdminsBypass: Bool(true)}
191191
if !cmp.Equal(v, want) {
192192
t.Errorf("Request body = %+v, want %+v", v, want)
193193
}

0 commit comments

Comments
 (0)