Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ProtectedBranchesApi.java #1119

Merged
merged 2 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java
Original file line number Diff line number Diff line change
@@ -196,6 +196,7 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
* <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>
* @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 branchName the name of the branch to protect, can be a wildcard
@@ -206,18 +207,42 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
* @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs
*/
@Deprecated
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
Integer allowedToPushUserId, Integer allowedToMergeUserId, Integer 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.
*
* <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.
*
* <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>
* @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 branchName the name of the branch to protect, can be a wildcard
@@ -229,9 +254,40 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
* @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs
*/
@Deprecated
public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName,
Integer allowedToPushUserId, Integer allowedToMergeUserId, Integer allowedToUnprotectUserId,
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()
.withParam("name", branchName, true)