Repository: xanzy/go-gitlab
Pull request #1141 (2021-05-04 09:53:51)

Add support for `allow_force_push` parameter of protected branches (new in Gitlab 13.11.0)
This PR adds support for the [new `allow_force_push` parameter](https://docs.gitlab.com/ee/api/protected_branches.html#protect-repository-branches) for protected branches introduced in [Gitlab 13.11](https://about.gitlab.com/releases/2021/04/22/gitlab-13-11-released/#force-push-option-for-protected-branches) 




Patch:
diff --git a/protected_branches.go b/protected_branches.go
index bcc0369..af3e7f2 100644
--- a/protected_branches.go
+++ b/protected_branches.go
@@ -41,6 +41,7 @@ type ProtectedBranch struct {
 	PushAccessLevels          []*BranchAccessDescription `json:"push_access_levels"`
 	MergeAccessLevels         []*BranchAccessDescription `json:"merge_access_levels"`
 	UnprotectAccessLevels     []*BranchAccessDescription `json:"unprotect_access_levels"`
+	AllowForcePush            bool                       `json:"allow_force_push"`
 	CodeOwnerApprovalRequired bool                       `json:"code_owner_approval_required"`
 }
 
@@ -123,6 +124,7 @@ type ProtectRepositoryBranchesOptions struct {
 	PushAccessLevel           *AccessLevelValue          `url:"push_access_level,omitempty" json:"push_access_level,omitempty"`
 	MergeAccessLevel          *AccessLevelValue          `url:"merge_access_level,omitempty" json:"merge_access_level,omitempty"`
 	UnprotectAccessLevel      *AccessLevelValue          `url:"unprotect_access_level,omitempty" json:"unprotect_access_level,omitempty"`
+	AllowForcePush            *bool                      `url:"allow_force_push,omitempty" json:"allow_force_push,omitempty"`
 	AllowedToPush             []*BranchPermissionOptions `url:"allowed_to_push,omitempty" json:"allowed_to_push,omitempty"`
 	AllowedToMerge            []*BranchPermissionOptions `url:"allowed_to_merge,omitempty" json:"allowed_to_merge,omitempty"`
 	AllowedToUnprotect        []*BranchPermissionOptions `url:"allowed_to_unprotect,omitempty" json:"allowed_to_unprotect,omitempty"`
@@ -194,7 +196,7 @@ type RequireCodeOwnerApprovalsOptions struct {
 	CodeOwnerApprovalRequired *bool `url:"code_owner_approval_required,omitempty" json:"code_owner_approval_required,omitempty"`
 }
 
-// RequireCodeOwnerApprovals updates the code owner approval.
+// RequireCodeOwnerApprovals updates the code owner approval option.
 //
 // Gitlab API docs:
 // https://docs.gitlab.com/ee/api/protected_branches.html#require-code-owner-approvals-for-a-single-branch


Test patch:
diff --git a/projects_test.go b/projects_test.go
index 4230ddf..3619797 100644
--- a/projects_test.go
+++ b/projects_test.go
@@ -807,6 +807,7 @@ func TestGetProjectApprovalRules(t *testing.T) {
 							AccessLevelDescription: "Maintainers",
 						},
 					},
+					AllowForcePush:            false,
 					CodeOwnerApprovalRequired: false,
 				},
 			},
@@ -986,6 +987,7 @@ func TestCreateProjectApprovalRule(t *testing.T) {
 						AccessLevelDescription: "Maintainers",
 					},
 				},
+				AllowForcePush:            false,
 				CodeOwnerApprovalRequired: false,
 			},
 		},
diff --git a/protected_branches_test.go b/protected_branches_test.go
index 622103a..ce4a9a6 100644
--- a/protected_branches_test.go
+++ b/protected_branches_test.go
@@ -66,6 +66,7 @@ func TestListProtectedBranches(t *testing.T) {
 					AccessLevelDescription: "Maintainers",
 				},
 			},
+			AllowForcePush:            false,
 			CodeOwnerApprovalRequired: false,
 		},
 	}
@@ -116,6 +117,7 @@ func TestListProtectedBranchesWithoutCodeOwnerApproval(t *testing.T) {
 					AccessLevelDescription: "Maintainers",
 				},
 			},
+			AllowForcePush:            false,
 			CodeOwnerApprovalRequired: false,
 		},
 	}
@@ -142,6 +144,7 @@ func TestProtectRepositoryBranches(t *testing.T) {
 			"access_level":40,
 			"access_level_description":"Maintainers"
 		}],
+		"allow_force_push":true,
 		"code_owner_approval_required":true
 	}`)
 	})
@@ -149,6 +152,7 @@ func TestProtectRepositoryBranches(t *testing.T) {
 		Name:                      String("master"),
 		PushAccessLevel:           AccessLevel(MaintainerPermissions),
 		MergeAccessLevel:          AccessLevel(MaintainerPermissions),
+		AllowForcePush:            Bool(true),
 		CodeOwnerApprovalRequired: Bool(true),
 	}
 	projects, _, err := client.ProtectedBranches.ProtectRepositoryBranches("1", opt)
@@ -170,6 +174,7 @@ func TestProtectRepositoryBranches(t *testing.T) {
 				AccessLevelDescription: "Maintainers",
 			},
 		},
+		AllowForcePush:            true,
 		CodeOwnerApprovalRequired: true,
 	}
 	if !reflect.DeepEqual(want, projects) {