diff --git a/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java b/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java index 854e2398a..91e4b4ce7 100644 --- a/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java +++ b/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java @@ -196,6 +196,7 @@ public ProtectedBranch protectBranch(Object projectIdOrPath, String branchName, *

NOTE: This method is only available to GitLab Starter, Bronze, or higher.

* *
GitLab Endpoint: POST /projects/:id/protected_branches
+ * @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. + * + *

NOTE: This method is only available to GitLab Starter, Bronze, or higher.

+ * + *
GitLab Endpoint: POST /projects/:id/protected_branches
+ * + * @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. * *

NOTE: This method is only available to GitLab Starter, Bronze, or higher.

* *
GitLab Endpoint: POST /projects/:id/protected_branches
+ * @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. + * + *

NOTE: This method is only available to GitLab Starter, Bronze, or higher.

+ * + *
GitLab Endpoint: POST /projects/:id/protected_branches
+ * + * @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)