Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CanAdminsBypass to CreateUpdateEnvironment #2727

Merged
merged 3 commits into from Mar 30, 2023
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.
Jump to
Jump to file
Failed to load files.
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
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
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