@@ -154,8 +154,8 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
154154 * @throws GitLabApiException if any exception occurs
155155 */
156156 public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
157- AccessLevel pushAccessLevel , AccessLevel mergeAccessLevel , AccessLevel unprotectAccessLevel ,
158- Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
157+ AccessLevel pushAccessLevel , AccessLevel mergeAccessLevel , AccessLevel unprotectAccessLevel ,
158+ Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
159159 Form formData = new GitLabApiForm ()
160160 .withParam ("name" , branchName , true )
161161 .withParam ("push_access_level" , pushAccessLevel )
@@ -184,10 +184,10 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
184184 * @throws GitLabApiException if any exception occurs
185185 */
186186 public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
187- Integer allowedToPushUserId , Integer allowedToMergeUserId , Integer allowedToUnprotectUserId ,
188- Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
187+ Integer allowedToPushUserId , Integer allowedToMergeUserId , Integer allowedToUnprotectUserId ,
188+ Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
189189
190- Form formData = new GitLabApiForm ()
190+ Form formData = new GitLabApiForm ()
191191 .withParam ("name" , branchName , true )
192192 .withParam ("allowed_to_push[][user_id]" , allowedToPushUserId )
193193 .withParam ("allowed_to_merge[][user_id]" , allowedToMergeUserId )
@@ -215,22 +215,46 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
215215 * @throws GitLabApiException if any exception occurs
216216 */
217217 public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
218- AllowedTo allowedToPush , AllowedTo allowedToMerge , AllowedTo allowedToUnprotect ,
219- Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
218+ AllowedTo allowedToPush , AllowedTo allowedToMerge , AllowedTo allowedToUnprotect ,
219+ Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
220220
221221 GitLabApiForm formData = new GitLabApiForm ()
222222 .withParam ("name" , branchName , true )
223223 .withParam ("code_owner_approval_required" , codeOwnerApprovalRequired );
224224
225- if (allowedToPush != null )
226- allowedToPush .getForm (formData , "allowed_to_push" );
227- if (allowedToMerge != null )
228- allowedToMerge .getForm (formData , "allowed_to_merge" );
229- if (allowedToUnprotect != null )
230- allowedToUnprotect .getForm (formData , "allowed_to_unprotect" );
225+ if (allowedToPush != null )
226+ allowedToPush .getForm (formData , "allowed_to_push" );
227+ if (allowedToMerge != null )
228+ allowedToMerge .getForm (formData , "allowed_to_merge" );
229+ if (allowedToUnprotect != null )
230+ allowedToUnprotect .getForm (formData , "allowed_to_unprotect" );
231231
232- Response response = post (Response .Status .CREATED , formData .asMap (),
232+ Response response = post (Response .Status .CREATED , formData .asMap (),
233233 "projects" , getProjectIdOrPath (projectIdOrPath ), "protected_branches" );
234234 return (response .readEntity (ProtectedBranch .class ));
235235 }
236+
237+ /**
238+ * Sets the code_owner_approval_required flag on the specified protected branch.
239+ *
240+ * <p>NOTE: This method is only available in GitLab Premium or higher.</p>
241+ *
242+ * <pre><code>GitLab Endpoint: PATCH /projects/:id/protected_branches/:branch_name?code_owner_approval_required=true</code></pre>
243+ *
244+ * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
245+ * @param branchName the name of the branch to protect, can be a wildcard
246+ * @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file.
247+ * @return the branch info for the protected branch
248+ * @throws GitLabApiException if any exception occurs
249+ */
250+ public ProtectedBranch setCodeOwnerApprovalRequired (Object projectIdOrPath , String branchName ,
251+ Boolean codeOwnerApprovalRequired ) throws GitLabApiException {
252+ Form formData = new GitLabApiForm ()
253+ .withParam ("code_owner_approval_required" , codeOwnerApprovalRequired );
254+
255+ Response response = patch (Response .Status .OK , formData .asMap (),
256+ "projects" , this .getProjectIdOrPath (projectIdOrPath ),
257+ "protected_branches" , urlEncode (branchName ));
258+ return (response .readEntity (ProtectedBranch .class ));
259+ }
236260}
0 commit comments