Skip to content

Commit c825410

Browse files
refactor!: Pass CreateDeploymentBranchPolicyRequest and UpdateDeploymentBranchPolicyRequest by value (#4382)
BREAKING CHANGE: `RepositoriesService.CreateDeploymentBranchPolicy` and `UpdateDeploymentBranchPolicy` now take `body` by value and the required `Name` field is of type `string`.
1 parent d0c2d21 commit c825410

5 files changed

Lines changed: 65 additions & 48 deletions

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ linters:
222222
- DependabotAlertState
223223
- DependabotEncryptedSecret
224224
- DependencyGraphSnapshot
225-
- DeploymentBranchPolicyRequest
226225
- EncryptedSecret
227226
- EnterpriseSecurityAnalysisSettings
228227
- ExternalGroup

github/github-accessors.go

Lines changed: 24 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 27 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/repos_deployment_branch_policies.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ type DeploymentBranchPolicyResponse struct {
2424
BranchPolicies []*DeploymentBranchPolicy `json:"branch_policies,omitempty"`
2525
}
2626

27-
// DeploymentBranchPolicyRequest represents a deployment branch policy request.
28-
type DeploymentBranchPolicyRequest struct {
29-
Name *string `json:"name,omitempty"`
27+
// CreateDeploymentBranchPolicyRequest represents a request to create a deployment branch policy.
28+
type CreateDeploymentBranchPolicyRequest struct {
29+
Name string `json:"name"`
3030
Type *string `json:"type,omitempty"`
3131
}
3232

33+
// UpdateDeploymentBranchPolicyRequest represents a request to update a deployment branch policy.
34+
type UpdateDeploymentBranchPolicyRequest struct {
35+
Name string `json:"name"`
36+
}
37+
3338
// ListDeploymentBranchPolicies lists the deployment branch policies for an environment.
3439
//
3540
// GitHub API docs: https://docs.github.com/rest/deployments/branch-policies?apiVersion=2022-11-28#list-deployment-branch-policies
@@ -83,7 +88,7 @@ func (s *RepositoriesService) GetDeploymentBranchPolicy(ctx context.Context, own
8388
// GitHub API docs: https://docs.github.com/rest/deployments/branch-policies?apiVersion=2022-11-28#create-a-deployment-branch-policy
8489
//
8590
//meta:operation POST /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies
86-
func (s *RepositoriesService) CreateDeploymentBranchPolicy(ctx context.Context, owner, repo, environment string, body *DeploymentBranchPolicyRequest) (*DeploymentBranchPolicy, *Response, error) {
91+
func (s *RepositoriesService) CreateDeploymentBranchPolicy(ctx context.Context, owner, repo, environment string, body CreateDeploymentBranchPolicyRequest) (*DeploymentBranchPolicy, *Response, error) {
8792
u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment-branch-policies", owner, repo, environment)
8893

8994
req, err := s.client.NewRequest(ctx, "POST", u, body)
@@ -105,7 +110,7 @@ func (s *RepositoriesService) CreateDeploymentBranchPolicy(ctx context.Context,
105110
// GitHub API docs: https://docs.github.com/rest/deployments/branch-policies?apiVersion=2022-11-28#update-a-deployment-branch-policy
106111
//
107112
//meta:operation PUT /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}
108-
func (s *RepositoriesService) UpdateDeploymentBranchPolicy(ctx context.Context, owner, repo, environment string, branchPolicyID int64, body *DeploymentBranchPolicyRequest) (*DeploymentBranchPolicy, *Response, error) {
113+
func (s *RepositoriesService) UpdateDeploymentBranchPolicy(ctx context.Context, owner, repo, environment string, branchPolicyID int64, body UpdateDeploymentBranchPolicyRequest) (*DeploymentBranchPolicy, *Response, error) {
109114
u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment-branch-policies/%v", owner, repo, environment, branchPolicyID)
110115

111116
req, err := s.client.NewRequest(ctx, "PUT", u, body)

github/repos_deployment_branch_policies_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestRepositoriesService_CreateDeploymentBranchPolicy(t *testing.T) {
9797
})
9898

9999
ctx := t.Context()
100-
got, _, err := client.Repositories.CreateDeploymentBranchPolicy(ctx, "o", "r", "e", &DeploymentBranchPolicyRequest{Name: Ptr("n"), Type: Ptr("branch")})
100+
got, _, err := client.Repositories.CreateDeploymentBranchPolicy(ctx, "o", "r", "e", CreateDeploymentBranchPolicyRequest{Name: "n", Type: Ptr("branch")})
101101
if err != nil {
102102
t.Errorf("Repositories.CreateDeploymentBranchPolicy returned error: %v", err)
103103
}
@@ -109,7 +109,7 @@ func TestRepositoriesService_CreateDeploymentBranchPolicy(t *testing.T) {
109109

110110
const methodName = "CreateDeploymentBranchPolicy"
111111
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
112-
got, resp, err := client.Repositories.CreateDeploymentBranchPolicy(ctx, "o", "r", "e", &DeploymentBranchPolicyRequest{Name: Ptr("n")})
112+
got, resp, err := client.Repositories.CreateDeploymentBranchPolicy(ctx, "o", "r", "e", CreateDeploymentBranchPolicyRequest{Name: "n"})
113113
if got != nil {
114114
t.Errorf("got non-nil Repositories.CreateDeploymentBranchPolicy response: %+v", got)
115115
}
@@ -127,7 +127,7 @@ func TestRepositoriesService_UpdateDeploymentBranchPolicy(t *testing.T) {
127127
})
128128

129129
ctx := t.Context()
130-
got, _, err := client.Repositories.UpdateDeploymentBranchPolicy(ctx, "o", "r", "e", 1, &DeploymentBranchPolicyRequest{Name: Ptr("n")})
130+
got, _, err := client.Repositories.UpdateDeploymentBranchPolicy(ctx, "o", "r", "e", 1, UpdateDeploymentBranchPolicyRequest{Name: "n"})
131131
if err != nil {
132132
t.Errorf("Repositories.UpdateDeploymentBranchPolicy returned error: %v", err)
133133
}
@@ -139,7 +139,7 @@ func TestRepositoriesService_UpdateDeploymentBranchPolicy(t *testing.T) {
139139

140140
const methodName = "UpdateDeploymentBranchPolicy"
141141
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
142-
got, resp, err := client.Repositories.UpdateDeploymentBranchPolicy(ctx, "o", "r", "e", 1, &DeploymentBranchPolicyRequest{Name: Ptr("n")})
142+
got, resp, err := client.Repositories.UpdateDeploymentBranchPolicy(ctx, "o", "r", "e", 1, UpdateDeploymentBranchPolicyRequest{Name: "n"})
143143
if got != nil {
144144
t.Errorf("got non-nil Repositories.UpdateDeploymentBranchPolicy response: %+v", got)
145145
}

0 commit comments

Comments
 (0)