Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions github/repos_environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}{
Expand All @@ -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"`
}

Expand Down
4 changes: 2 additions & 2 deletions github/repos_environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down