From 815e2f153609f6e5b825b2598a7fefaca15ee96d Mon Sep 17 00:00:00 2001 From: hpeacher <98431073+hpeacher@users.noreply.github.com> Date: Mon, 29 Apr 2024 11:55:44 -0500 Subject: [PATCH 1/2] Update ProtectedBranchesApi.java Based on issue #874 Added a new method with Long as data type for UserId. Added deprecated tag in the old method that used Integer type. --- .../gitlab4j/api/ProtectedBranchesApi.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java b/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java index 854e2398a..51028ccaf 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 * * @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,12 +207,35 @@ 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. * From edf7fb415250052d495fb5c5f2e88c219605be46 Mon Sep 17 00:00:00 2001 From: Jeremie Bresson Date: Fri, 17 May 2024 11:19:13 +0200 Subject: [PATCH 2/2] Fix compile error --- .../gitlab4j/api/ProtectedBranchesApi.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java b/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java index 51028ccaf..91e4b4ce7 100644 --- a/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java +++ b/src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java @@ -196,7 +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 + * @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 @@ -242,6 +242,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, 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 @@ -253,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)