Skip to content

Commit bc35080

Browse files
hpeacherjmini
andauthored
Update ProtectedBranchesApi to use Long instead of Integer for user ids (#1119)
--------- Co-authored-by: Jeremie Bresson <[email protected]>
1 parent 224f4c5 commit bc35080

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
196196
* <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
197197
*
198198
* <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
199+
* @deprecated use {@link #protectBranch(Object, String, Long, Long, Long, Boolean)} instead.
199200
*
200201
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
201202
* @param branchName the name of the branch to protect, can be a wildcard
@@ -206,18 +207,42 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
206207
* @return the branch info for the protected branch
207208
* @throws GitLabApiException if any exception occurs
208209
*/
210+
@Deprecated
209211
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
210212
Integer allowedToPushUserId, Integer allowedToMergeUserId, Integer allowedToUnprotectUserId,
211213
Boolean codeOwnerApprovalRequired) throws GitLabApiException {
212214
return protectBranch(projectIdOrPath, branchName, allowedToPushUserId, allowedToMergeUserId, allowedToUnprotectUserId, codeOwnerApprovalRequired, null);
213215
}
214216

217+
/**
218+
* Protects a single repository branch or several project repository branches using a wildcard protected branch.
219+
*
220+
* <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
221+
*
222+
* <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
223+
*
224+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
225+
* @param branchName the name of the branch to protect, can be a wildcard
226+
* @param allowedToPushUserId user ID allowed to push, can be null
227+
* @param allowedToMergeUserId user ID allowed to merge, can be null
228+
* @param allowedToUnprotectUserId user ID allowed to unprotect, can be null
229+
* @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
230+
* @return the branch info for the protected branch
231+
* @throws GitLabApiException if any exception occurs
232+
*/
233+
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
234+
Long allowedToPushUserId, Long allowedToMergeUserId, Long allowedToUnprotectUserId,
235+
Boolean codeOwnerApprovalRequired) throws GitLabApiException {
236+
return protectBranch(projectIdOrPath, branchName, allowedToPushUserId, allowedToMergeUserId, allowedToUnprotectUserId, codeOwnerApprovalRequired, null);
237+
}
238+
215239
/**
216240
* Protects a single repository branch or several project repository branches using a wildcard protected branch.
217241
*
218242
* <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
219243
*
220244
* <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
245+
* @deprecated use {@link #protectBranch(Object, String, Long, Long, Long, Boolean, Boolean)} instead.
221246
*
222247
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
223248
* @param branchName the name of the branch to protect, can be a wildcard
@@ -229,9 +254,40 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
229254
* @return the branch info for the protected branch
230255
* @throws GitLabApiException if any exception occurs
231256
*/
257+
@Deprecated
232258
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
233259
Integer allowedToPushUserId, Integer allowedToMergeUserId, Integer allowedToUnprotectUserId,
234260
Boolean codeOwnerApprovalRequired, Boolean allowForcedPush) throws GitLabApiException {
261+
return protectBranch(projectIdOrPath, branchName, toLong(allowedToPushUserId), toLong(allowedToMergeUserId), toLong(allowedToUnprotectUserId), codeOwnerApprovalRequired, allowForcedPush);
262+
}
263+
264+
private static Long toLong(Integer value) {
265+
if(value == null) {
266+
return null;
267+
}
268+
return value.longValue();
269+
}
270+
271+
/**
272+
* Protects a single repository branch or several project repository branches using a wildcard protected branch.
273+
*
274+
* <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
275+
*
276+
* <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
277+
*
278+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
279+
* @param branchName the name of the branch to protect, can be a wildcard
280+
* @param allowedToPushUserId user ID allowed to push, can be null
281+
* @param allowedToMergeUserId user ID allowed to merge, can be null
282+
* @param allowedToUnprotectUserId user ID allowed to unprotect, can be null
283+
* @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
284+
* @param allowForcedPush when enabled, members who can push to this branch can also force push. (default: false)
285+
* @return the branch info for the protected branch
286+
* @throws GitLabApiException if any exception occurs
287+
*/
288+
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
289+
Long allowedToPushUserId, Long allowedToMergeUserId, Long allowedToUnprotectUserId,
290+
Boolean codeOwnerApprovalRequired, Boolean allowForcedPush) throws GitLabApiException {
235291

236292
Form formData = new GitLabApiForm()
237293
.withParam("name", branchName, true)

0 commit comments

Comments
 (0)