@@ -136,7 +136,7 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName)
136136 * @throws GitLabApiException if any exception occurs
137137 */
138138 public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName , AccessLevel pushAccessLevel , AccessLevel mergeAccessLevel ) throws GitLabApiException {
139- return (protectBranch (projectIdOrPath , branchName , pushAccessLevel , mergeAccessLevel , null , null ));
139+ return (protectBranch (projectIdOrPath , branchName , pushAccessLevel , mergeAccessLevel , null , null , null ));
140140 }
141141
142142 /**
@@ -152,16 +152,39 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
152152 * @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
153153 * @return the branch info for the protected branch
154154 * @throws GitLabApiException if any exception occurs
155+ * @see ProtectedBranchesApi#protectBranch(Object, String, AccessLevel, AccessLevel, AccessLevel, Boolean, Boolean)
155156 */
156157 public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
157158 AccessLevel pushAccessLevel , AccessLevel mergeAccessLevel , AccessLevel unprotectAccessLevel ,
158159 Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
159- Form formData = new GitLabApiForm ()
160+ return protectBranch (projectIdOrPath , branchName , pushAccessLevel , mergeAccessLevel , unprotectAccessLevel , codeOwnerApprovalRequired , null );
161+ }
162+
163+ /**
164+ * Protects a single repository branch or several project repository branches using a wildcard protected branch.
165+ *
166+ * <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
167+ *
168+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
169+ * @param branchName the name of the branch to protect, can be a wildcard
170+ * @param pushAccessLevel access levels allowed to push (defaults: 40, maintainer access level)
171+ * @param mergeAccessLevel access levels allowed to merge (defaults: 40, maintainer access level)
172+ * @param unprotectAccessLevel access levels allowed to unprotect (defaults: 40, maintainer access level)
173+ * @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
174+ * @param allowForcedPush when enabled, members who can push to this branch can also force push. (default: false)
175+ * @return the branch info for the protected branch
176+ * @throws GitLabApiException if any exception occurs
177+ */
178+ public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
179+ AccessLevel pushAccessLevel , AccessLevel mergeAccessLevel , AccessLevel unprotectAccessLevel ,
180+ Boolean codeOwnerApprovalRequired , Boolean allowForcedPush ) throws GitLabApiException {
181+ GitLabApiForm formData = new GitLabApiForm ()
160182 .withParam ("name" , branchName , true )
161183 .withParam ("push_access_level" , pushAccessLevel )
162184 .withParam ("merge_access_level" , mergeAccessLevel )
163185 .withParam ("unprotect_access_level" , unprotectAccessLevel )
164- .withParam ("code_owner_approval_required" , codeOwnerApprovalRequired );
186+ .withParam ("code_owner_approval_required" , codeOwnerApprovalRequired )
187+ .withParam ("allow_force_push" , allowForcedPush );
165188 Response response = post (Response .Status .CREATED , formData .asMap (),
166189 "projects" , getProjectIdOrPath (projectIdOrPath ), "protected_branches" );
167190 return (response .readEntity (ProtectedBranch .class ));
@@ -186,13 +209,37 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
186209 public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
187210 Integer allowedToPushUserId , Integer allowedToMergeUserId , Integer allowedToUnprotectUserId ,
188211 Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
212+ return protectBranch (projectIdOrPath , branchName , allowedToPushUserId , allowedToMergeUserId , allowedToUnprotectUserId , codeOwnerApprovalRequired , null );
213+ }
214+
215+ /**
216+ * Protects a single repository branch or several project repository branches using a wildcard protected branch.
217+ *
218+ * <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
219+ *
220+ * <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
221+ *
222+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
223+ * @param branchName the name of the branch to protect, can be a wildcard
224+ * @param allowedToPushUserId user ID allowed to push, can be null
225+ * @param allowedToMergeUserId user ID allowed to merge, can be null
226+ * @param allowedToUnprotectUserId user ID allowed to unprotect, can be null
227+ * @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
228+ * @param allowForcedPush when enabled, members who can push to this branch can also force push. (default: false)
229+ * @return the branch info for the protected branch
230+ * @throws GitLabApiException if any exception occurs
231+ */
232+ public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
233+ Integer allowedToPushUserId , Integer allowedToMergeUserId , Integer allowedToUnprotectUserId ,
234+ Boolean codeOwnerApprovalRequired , Boolean allowForcedPush ) throws GitLabApiException {
189235
190236 Form formData = new GitLabApiForm ()
191237 .withParam ("name" , branchName , true )
192238 .withParam ("allowed_to_push[][user_id]" , allowedToPushUserId )
193239 .withParam ("allowed_to_merge[][user_id]" , allowedToMergeUserId )
194240 .withParam ("allowed_to_unprotect[][user_id]" , allowedToUnprotectUserId )
195- .withParam ("code_owner_approval_required" , codeOwnerApprovalRequired );
241+ .withParam ("code_owner_approval_required" , codeOwnerApprovalRequired )
242+ .withParam ("allow_force_push" , allowForcedPush );
196243 Response response = post (Response .Status .CREATED , formData .asMap (),
197244 "projects" , getProjectIdOrPath (projectIdOrPath ), "protected_branches" );
198245 return (response .readEntity (ProtectedBranch .class ));
0 commit comments