Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
59f726a5
Commit
59f726a5
authored
Dec 26, 2023
by
Jeremie Bresson
Browse files
Merge remote-tracking branch 'origin/main' into 6.x
parents
ac4fa952
ddb244e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ProtectedBranchesApi.java
View file @
59f726a5
...
@@ -136,7 +136,7 @@ public class ProtectedBranchesApi extends AbstractApi {
...
@@ -136,7 +136,7 @@ public class ProtectedBranchesApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
* @throws GitLabApiException if any exception occurs
*/
*/
public
ProtectedBranch
protectBranch
(
Object
projectIdOrPath
,
String
branchName
,
AccessLevel
pushAccessLevel
,
AccessLevel
mergeAccessLevel
)
throws
GitLabApiException
{
public
ProtectedBranch
protectBranch
(
Object
projectIdOrPath
,
String
branchName
,
AccessLevel
pushAccessLevel
,
AccessLevel
mergeAccessLevel
)
throws
GitLabApiException
{
return
(
protectBranch
(
projectIdOrPath
,
branchName
,
pushAccessLevel
,
mergeAccessLevel
,
null
,
null
));
return
(
protectBranch
(
projectIdOrPath
,
branchName
,
pushAccessLevel
,
mergeAccessLevel
,
null
,
null
,
null
));
}
}
/**
/**
...
@@ -152,16 +152,39 @@ public class ProtectedBranchesApi extends AbstractApi {
...
@@ -152,16 +152,39 @@ public class ProtectedBranchesApi extends AbstractApi {
* @param codeOwnerApprovalRequired prevent pushes to this branch if it matches an item in the CODEOWNERS file. (defaults: false)
* @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
* @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs
* @throws GitLabApiException if any exception occurs
* @see ProtectedBranchesApi#protectBranch(Object, String, AccessLevel, AccessLevel, AccessLevel, Boolean, Boolean)
*/
*/
public
ProtectedBranch
protectBranch
(
Object
projectIdOrPath
,
String
branchName
,
public
ProtectedBranch
protectBranch
(
Object
projectIdOrPath
,
String
branchName
,
AccessLevel
pushAccessLevel
,
AccessLevel
mergeAccessLevel
,
AccessLevel
unprotectAccessLevel
,
AccessLevel
pushAccessLevel
,
AccessLevel
mergeAccessLevel
,
AccessLevel
unprotectAccessLevel
,
Boolean
codeOwnerApprovalRequired
)
throws
GitLabApiException
{
Boolean
codeOwnerApprovalRequired
)
throws
GitLabApiException
{
Form
formData
=
new
GitLabApiForm
()
return
protectBranch
(
projectIdOrPath
,
branchName
,
pushAccessLevel
,
mergeAccessLevel
,
unprotectAccessLevel
,
codeOwnerApprovalRequired
,
null
);
}
/**
* Protects a single repository branch or several project repository branches using a wildcard protected branch.
*
* <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 pushAccessLevel access levels allowed to push (defaults: 40, maintainer access level)
* @param mergeAccessLevel access levels allowed to merge (defaults: 40, maintainer access level)
* @param unprotectAccessLevel access levels allowed to unprotect (defaults: 40, maintainer access level)
* @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
,
AccessLevel
pushAccessLevel
,
AccessLevel
mergeAccessLevel
,
AccessLevel
unprotectAccessLevel
,
Boolean
codeOwnerApprovalRequired
,
Boolean
allowForcedPush
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"name"
,
branchName
,
true
)
.
withParam
(
"name"
,
branchName
,
true
)
.
withParam
(
"push_access_level"
,
pushAccessLevel
)
.
withParam
(
"push_access_level"
,
pushAccessLevel
)
.
withParam
(
"merge_access_level"
,
mergeAccessLevel
)
.
withParam
(
"merge_access_level"
,
mergeAccessLevel
)
.
withParam
(
"unprotect_access_level"
,
unprotectAccessLevel
)
.
withParam
(
"unprotect_access_level"
,
unprotectAccessLevel
)
.
withParam
(
"code_owner_approval_required"
,
codeOwnerApprovalRequired
);
.
withParam
(
"code_owner_approval_required"
,
codeOwnerApprovalRequired
)
.
withParam
(
"allow_force_push"
,
allowForcedPush
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
.
asMap
(),
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
.
asMap
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"protected_branches"
);
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"protected_branches"
);
return
(
response
.
readEntity
(
ProtectedBranch
.
class
));
return
(
response
.
readEntity
(
ProtectedBranch
.
class
));
...
@@ -186,13 +209,37 @@ public class ProtectedBranchesApi extends AbstractApi {
...
@@ -186,13 +209,37 @@ public class ProtectedBranchesApi extends AbstractApi {
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
);
}
/**
* 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
,
Integer
allowedToPushUserId
,
Integer
allowedToMergeUserId
,
Integer
allowedToUnprotectUserId
,
Boolean
codeOwnerApprovalRequired
,
Boolean
allowForcedPush
)
throws
GitLabApiException
{
Form
formData
=
new
GitLabApiForm
()
Form
formData
=
new
GitLabApiForm
()
.
withParam
(
"name"
,
branchName
,
true
)
.
withParam
(
"name"
,
branchName
,
true
)
.
withParam
(
"allowed_to_push[][user_id]"
,
allowedToPushUserId
)
.
withParam
(
"allowed_to_push[][user_id]"
,
allowedToPushUserId
)
.
withParam
(
"allowed_to_merge[][user_id]"
,
allowedToMergeUserId
)
.
withParam
(
"allowed_to_merge[][user_id]"
,
allowedToMergeUserId
)
.
withParam
(
"allowed_to_unprotect[][user_id]"
,
allowedToUnprotectUserId
)
.
withParam
(
"allowed_to_unprotect[][user_id]"
,
allowedToUnprotectUserId
)
.
withParam
(
"code_owner_approval_required"
,
codeOwnerApprovalRequired
);
.
withParam
(
"code_owner_approval_required"
,
codeOwnerApprovalRequired
)
.
withParam
(
"allow_force_push"
,
allowForcedPush
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
.
asMap
(),
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
.
asMap
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"protected_branches"
);
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"protected_branches"
);
return
(
response
.
readEntity
(
ProtectedBranch
.
class
));
return
(
response
.
readEntity
(
ProtectedBranch
.
class
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment