@@ -136,7 +136,7 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName)
136
136
* @throws GitLabApiException if any exception occurs
137
137
*/
138
138
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 ));
140
140
}
141
141
142
142
/**
@@ -152,16 +152,39 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
152
152
* @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
153
153
* @return the branch info for the protected branch
154
154
* @throws GitLabApiException if any exception occurs
155
+ * @see ProtectedBranchesApi#protectBranch(Object, String, AccessLevel, AccessLevel, AccessLevel, Boolean, Boolean)
155
156
*/
156
157
public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
157
158
AccessLevel pushAccessLevel , AccessLevel mergeAccessLevel , AccessLevel unprotectAccessLevel ,
158
159
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 ()
160
182
.withParam ("name" , branchName , true )
161
183
.withParam ("push_access_level" , pushAccessLevel )
162
184
.withParam ("merge_access_level" , mergeAccessLevel )
163
185
.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 );
165
188
Response response = post (Response .Status .CREATED , formData .asMap (),
166
189
"projects" , getProjectIdOrPath (projectIdOrPath ), "protected_branches" );
167
190
return (response .readEntity (ProtectedBranch .class ));
@@ -186,13 +209,37 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
186
209
public ProtectedBranch protectBranch (Object projectIdOrPath , String branchName ,
187
210
Integer allowedToPushUserId , Integer allowedToMergeUserId , Integer allowedToUnprotectUserId ,
188
211
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 {
189
235
190
236
Form formData = new GitLabApiForm ()
191
237
.withParam ("name" , branchName , true )
192
238
.withParam ("allowed_to_push[][user_id]" , allowedToPushUserId )
193
239
.withParam ("allowed_to_merge[][user_id]" , allowedToMergeUserId )
194
240
.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 );
196
243
Response response = post (Response .Status .CREATED , formData .asMap (),
197
244
"projects" , getProjectIdOrPath (projectIdOrPath ), "protected_branches" );
198
245
return (response .readEntity (ProtectedBranch .class ));
0 commit comments