Repository: google/go-github (Go)

Issue:
Add type field on DeploymentBranchPolicy
Deployment branch policies now support a type field to specify the policy type, "branch" or "tag"
https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#create-a-deployment-branch-policy


Discussion:

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 78a184e6c80..199c9b8a37d 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -5582,6 +5582,14 @@ func (d *DeploymentBranchPolicy) GetNodeID() string {
 	return *d.NodeID
 }
 
+// GetType returns the Type field if it's non-nil, zero value otherwise.
+func (d *DeploymentBranchPolicy) GetType() string {
+	if d == nil || d.Type == nil {
+		return ""
+	}
+	return *d.Type
+}
+
 // GetName returns the Name field if it's non-nil, zero value otherwise.
 func (d *DeploymentBranchPolicyRequest) GetName() string {
 	if d == nil || d.Name == nil {
@@ -5590,6 +5598,14 @@ func (d *DeploymentBranchPolicyRequest) GetName() string {
 	return *d.Name
 }
 
+// GetType returns the Type field if it's non-nil, zero value otherwise.
+func (d *DeploymentBranchPolicyRequest) GetType() string {
+	if d == nil || d.Type == nil {
+		return ""
+	}
+	return *d.Type
+}
+
 // GetTotalCount returns the TotalCount field if it's non-nil, zero value otherwise.
 func (d *DeploymentBranchPolicyResponse) GetTotalCount() int {
 	if d == nil || d.TotalCount == nil {
diff --git a/github/repos_deployment_branch_policies.go b/github/repos_deployment_branch_policies.go
index 8c4628b39bc..32bf72ccab5 100644
--- a/github/repos_deployment_branch_policies.go
+++ b/github/repos_deployment_branch_policies.go
@@ -15,6 +15,7 @@ type DeploymentBranchPolicy struct {
 	Name   *string `json:"name,omitempty"`
 	ID     *int64  `json:"id,omitempty"`
 	NodeID *string `json:"node_id,omitempty"`
+	Type   *string `json:"type,omitempty"`
 }
 
 // DeploymentBranchPolicyResponse represents the slightly different format of response that comes back when you list deployment branch policies.
@@ -26,6 +27,7 @@ type DeploymentBranchPolicyResponse struct {
 // DeploymentBranchPolicyRequest represents a deployment branch policy request.
 type DeploymentBranchPolicyRequest struct {
 	Name *string `json:"name,omitempty"`
+	Type *string `json:"type,omitempty"`
 }
 
 // ListDeploymentBranchPolicies lists the deployment branch policies for an environment.


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 54c89eb9876..d179a927750 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -6570,6 +6570,16 @@ func TestDeploymentBranchPolicy_GetNodeID(tt *testing.T) {
 	d.GetNodeID()
 }
 
+func TestDeploymentBranchPolicy_GetType(tt *testing.T) {
+	var zeroValue string
+	d := &DeploymentBranchPolicy{Type: &zeroValue}
+	d.GetType()
+	d = &DeploymentBranchPolicy{}
+	d.GetType()
+	d = nil
+	d.GetType()
+}
+
 func TestDeploymentBranchPolicyRequest_GetName(tt *testing.T) {
 	var zeroValue string
 	d := &DeploymentBranchPolicyRequest{Name: &zeroValue}
@@ -6580,6 +6590,16 @@ func TestDeploymentBranchPolicyRequest_GetName(tt *testing.T) {
 	d.GetName()
 }
 
+func TestDeploymentBranchPolicyRequest_GetType(tt *testing.T) {
+	var zeroValue string
+	d := &DeploymentBranchPolicyRequest{Type: &zeroValue}
+	d.GetType()
+	d = &DeploymentBranchPolicyRequest{}
+	d.GetType()
+	d = nil
+	d.GetType()
+}
+
 func TestDeploymentBranchPolicyResponse_GetTotalCount(tt *testing.T) {
 	var zeroValue int
 	d := &DeploymentBranchPolicyResponse{TotalCount: &zeroValue}
diff --git a/github/repos_deployment_branch_policies_test.go b/github/repos_deployment_branch_policies_test.go
index 69bffac86ed..9d2acd199d3 100644
--- a/github/repos_deployment_branch_policies_test.go
+++ b/github/repos_deployment_branch_policies_test.go
@@ -83,16 +83,16 @@ func TestRepositoriesService_CreateDeploymentBranchPolicy(t *testing.T) {
 
 	mux.HandleFunc("/repos/o/r/environments/e/deployment-branch-policies", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "POST")
-		fmt.Fprint(w, `{"id":1}`)
+		fmt.Fprint(w, `{"id":1, "type":"branch"}`)
 	})
 
 	ctx := context.Background()
-	got, _, err := client.Repositories.CreateDeploymentBranchPolicy(ctx, "o", "r", "e", &DeploymentBranchPolicyRequest{Name: String("n")})
+	got, _, err := client.Repositories.CreateDeploymentBranchPolicy(ctx, "o", "r", "e", &DeploymentBranchPolicyRequest{Name: String("n"), Type: String("branch")})
 	if err != nil {
 		t.Errorf("Repositories.CreateDeploymentBranchPolicy returned error: %v", err)
 	}
 
-	want := &DeploymentBranchPolicy{ID: Int64(1)}
+	want := &DeploymentBranchPolicy{ID: Int64(1), Type: String("branch")}
 	if !reflect.DeepEqual(got, want) {
 		t.Errorf("Repositories.CreateDeploymentBranchPolicy = %+v, want %+v", got, want)
 	}