Unverified Commit bc350802 authored by hpeacher's avatar hpeacher Committed by GitHub
Browse files

Update ProtectedBranchesApi to use Long instead of Integer for user ids (#1119)



---------

Co-authored-by: default avatarJeremie Bresson <jeremie.bresson@unblu.com>
parent 224f4c5b
...@@ -196,6 +196,7 @@ public class ProtectedBranchesApi extends AbstractApi { ...@@ -196,6 +196,7 @@ public class ProtectedBranchesApi extends AbstractApi {
* <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p> * <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
* *
* <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre> * <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
* @deprecated use {@link #protectBranch(Object, String, Long, Long, Long, Boolean)} instead.
* *
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param branchName the name of the branch to protect, can be a wildcard * @param branchName the name of the branch to protect, can be a wildcard
...@@ -206,18 +207,42 @@ public class ProtectedBranchesApi extends AbstractApi { ...@@ -206,18 +207,42 @@ public class ProtectedBranchesApi extends AbstractApi {
* @return the branch info for the protected branch * @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
@Deprecated
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName, public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
Integer allowedToPushUserId, Integer allowedToMergeUserId, Integer allowedToUnprotectUserId, Integer allowedToPushUserId, Integer allowedToMergeUserId, Integer allowedToUnprotectUserId,
Boolean codeOwnerApprovalRequired) throws GitLabApiException { Boolean codeOwnerApprovalRequired) throws GitLabApiException {
return protectBranch(projectIdOrPath, branchName, allowedToPushUserId, allowedToMergeUserId, allowedToUnprotectUserId, codeOwnerApprovalRequired, null); return protectBranch(projectIdOrPath, branchName, allowedToPushUserId, allowedToMergeUserId, allowedToUnprotectUserId, codeOwnerApprovalRequired, null);
} }
/**
* Protects a single repository branch or several project repository branches using a wildcard protected branch.
*
* <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
*
* <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param branchName the name of the branch to protect, can be a wildcard
* @param allowedToPushUserId user ID allowed to push, can be null
* @param allowedToMergeUserId user ID allowed to merge, can be null
* @param allowedToUnprotectUserId user ID allowed to unprotect, can be null
* @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
* @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs
*/
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
Long allowedToPushUserId, Long allowedToMergeUserId, Long allowedToUnprotectUserId,
Boolean codeOwnerApprovalRequired) throws GitLabApiException {
return protectBranch(projectIdOrPath, branchName, allowedToPushUserId, allowedToMergeUserId, allowedToUnprotectUserId, codeOwnerApprovalRequired, null);
}
/** /**
* Protects a single repository branch or several project repository branches using a wildcard protected branch. * Protects a single repository branch or several project repository branches using a wildcard protected branch.
* *
* <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p> * <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
* *
* <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre> * <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
* @deprecated use {@link #protectBranch(Object, String, Long, Long, Long, Boolean, Boolean)} instead.
* *
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param branchName the name of the branch to protect, can be a wildcard * @param branchName the name of the branch to protect, can be a wildcard
...@@ -229,9 +254,40 @@ public class ProtectedBranchesApi extends AbstractApi { ...@@ -229,9 +254,40 @@ public class ProtectedBranchesApi extends AbstractApi {
* @return the branch info for the protected branch * @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
@Deprecated
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName, public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
Integer allowedToPushUserId, Integer allowedToMergeUserId, Integer allowedToUnprotectUserId, Integer allowedToPushUserId, Integer allowedToMergeUserId, Integer allowedToUnprotectUserId,
Boolean codeOwnerApprovalRequired, Boolean allowForcedPush) throws GitLabApiException { Boolean codeOwnerApprovalRequired, Boolean allowForcedPush) throws GitLabApiException {
return protectBranch(projectIdOrPath, branchName, toLong(allowedToPushUserId), toLong(allowedToMergeUserId), toLong(allowedToUnprotectUserId), codeOwnerApprovalRequired, allowForcedPush);
}
private static Long toLong(Integer value) {
if(value == null) {
return null;
}
return value.longValue();
}
/**
* Protects a single repository branch or several project repository branches using a wildcard protected branch.
*
* <p>NOTE: This method is only available to GitLab Starter, Bronze, or higher.</p>
*
* <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param branchName the name of the branch to protect, can be a wildcard
* @param allowedToPushUserId user ID allowed to push, can be null
* @param allowedToMergeUserId user ID allowed to merge, can be null
* @param allowedToUnprotectUserId user ID allowed to unprotect, can be null
* @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
* @param allowForcedPush when enabled, members who can push to this branch can also force push. (default: false)
* @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs
*/
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
Long allowedToPushUserId, Long allowedToMergeUserId, Long allowedToUnprotectUserId,
Boolean codeOwnerApprovalRequired, Boolean allowForcedPush) throws GitLabApiException {
Form formData = new GitLabApiForm() Form formData = new GitLabApiForm()
.withParam("name", branchName, true) .withParam("name", branchName, true)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment