@@ -154,8 +154,8 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
154
154
* @throws GitLabApiException if any exception occurs
155
155
*/
156
156
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 {
159
159
Form formData = new GitLabApiForm ()
160
160
.withParam ("name" , branchName , true )
161
161
.withParam ("push_access_level" , pushAccessLevel )
@@ -184,10 +184,10 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
184
184
* @throws GitLabApiException if any exception occurs
185
185
*/
186
186
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 {
189
189
190
- Form formData = new GitLabApiForm ()
190
+ Form formData = new GitLabApiForm ()
191
191
.withParam ("name" , branchName , true )
192
192
.withParam ("allowed_to_push[][user_id]" , allowedToPushUserId )
193
193
.withParam ("allowed_to_merge[][user_id]" , allowedToMergeUserId )
@@ -215,22 +215,46 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
215
215
* @throws GitLabApiException if any exception occurs
216
216
*/
217
217
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 {
220
220
221
221
GitLabApiForm formData = new GitLabApiForm ()
222
222
.withParam ("name" , branchName , true )
223
223
.withParam ("code_owner_approval_required" , codeOwnerApprovalRequired );
224
224
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" );
231
231
232
- Response response = post (Response .Status .CREATED , formData .asMap (),
232
+ Response response = post (Response .Status .CREATED , formData .asMap (),
233
233
"projects" , getProjectIdOrPath (projectIdOrPath ), "protected_branches" );
234
234
return (response .readEntity (ProtectedBranch .class ));
235
235
}
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
+ }
236
260
}
0 commit comments