CreateProtectedBranch - Create a protected branch
Creates a protected branch for a specified repository.
|
Applicable editions |
Central edition, Region edition |
Service endpoint and authorization information
-
Obtain the service endpoint. You must use the endpoint to replace {domain} in the API request syntax.
-
Obtain the organizationId. This parameter is required only for the Central edition. To obtain the organization ID, go to the Basic Information page in the Organization Management Console.
|
Product |
Resource |
Required permission |
|
Code Management |
Protected branches |
Read and write |
Request syntax
Central edition
POST https://{domain}/oapi/v1/codeup/organizations/{organizationId}/repositories/{repositoryId}/protectedBranches
Region edition
POST https://{domain}/oapi/v1/codeup/repositories/{repositoryId}/protectedBranches
Request headers
|
Parameter |
Type |
Required |
Description |
Example value |
|
x-yunxiao-token |
string |
Yes |
Your personal access token. |
pt-0fh3****0fbG_35af****0484 |
Request parameters
|
Parameter |
Type |
Location |
Required |
Description |
Example value |
|
organizationId |
string |
path |
|
The organization ID. |
60d54f3daccf2bbd6659f3ad |
|
repositoryId |
string |
path |
Yes |
The repository ID or the full path URL-encoded. |
2813489 or 60de7a6852743a5162b5f957%2FDemoRepo |
| - |
object |
body |
No |
||
|
allowMergeRoles |
array[integer] |
body |
No |
The list of roles allowed to merge changes: 40 for administrators and 30 for developers. |
[40, 30] |
|
allowMergeUserIds |
array[string] |
body |
No |
The list of user IDs allowed to merge changes. |
["62c795xxxb468af8"] |
|
allowPushRoles |
array[integer] |
body |
No |
The list of roles allowed to push changes: 40 for administrators and 30 for developers. |
[40, 30] |
|
allowPushUserIds |
array[string] |
body |
No |
The list of user IDs allowed to push changes. |
["62c795xxxb468af8"] |
|
branch |
string |
body |
Yes |
The name of the protected branch. |
master |
| mergeRequestSetting |
object |
body |
No |
Require code review before merging. |
|
|
allowMergeRequestRoles |
array[integer] |
body |
No |
The list of roles allowed to submit merge requests. |
[40, 30] |
|
defaultAssignees |
array[string] |
body |
No |
The list of default reviewer IDs. |
["62c795xxxb468af8"] |
|
isAllowSelfApproval |
boolean |
body |
No |
Allow the author to approve their own code review. |
false |
|
isAllowSourceBranchPushUserApproval |
boolean |
body |
No |
Allow committers of the source branch to approve merge requests. |
false |
|
isRequireDiscussionProcessed |
boolean |
body |
No |
Is it required to review all resolved items? |
true |
|
isRequired |
boolean |
body |
No |
Enable the requirement for code review before merging. |
true |
|
isResetApprovalWhenNewPush |
boolean |
body |
No |
Reset the review status when you push. |
true |
|
minimumApproval |
integer |
body |
No |
The minimum number of approvals required. This setting applies only in general mode. |
1 |
|
mrMode |
string |
body |
No |
Review mode can be general mode or CodeOwner mode. |
general |
|
whiteList |
string |
body |
No |
The file whitelist for code review. Enter file paths, separated by line feeds. Use English-style wildcard characters. |
*.java |
| testSetting |
object |
body |
No |
Require automated status checks before merging. |
|
| checkCheckRunConfig |
object |
body |
No |
Run checks. |
|
| checkRunCheckItems |
array |
body |
No |
The list of configuration items. |
|
| - |
object |
body |
No |
||
|
id |
string |
body |
No |
Enter the person ID. |
62c795xxxb468af8 |
|
name |
string |
body |
No |
The name of the check run. |
default-test-check-run-name |
|
required |
boolean |
body |
No |
Is this a checkpoint? |
true |
|
type |
string |
body |
No |
The type of the person who created the check run: User. |
User |
| checkCommitStatusConfig |
object |
body |
No |
Commit status. |
|
| commitStatusCheckItems |
array |
body |
No |
The list of configuration items. |
|
| - |
object |
body |
No |
||
|
context |
string |
body |
No |
The name of the third-party commit status. This name is used as the matching item for gatekeeper checks. |
default-context |
|
required |
boolean |
body |
No |
Is this a checkpoint? |
true |
| checkConfig |
object |
body |
No |
Pipeline checks. |
|
| checkItems |
array |
body |
No |
The list of configuration items. |
|
| - |
object |
body |
No |
||
|
isRequired |
boolean |
body |
No |
This is a gatekeeper check. |
true |
|
pipelineId |
integer |
body |
No |
The pipeline ID. |
1880578 |
|
pipelineName |
string |
body |
No |
The pipeline name. |
Test code inspection |
| checkTaskQualityConfig |
object |
body |
No |
Code inspection task. |
|
|
bizNo |
string |
body |
No |
The pipeline number of the inspection task. |
202207270957450000110900090430096 |
|
enabled |
boolean |
body |
No |
Enable code inspection. |
true |
|
message |
string |
body |
No |
A description. |
codeup-demo test code inspection task |
|
taskName |
string |
body |
No |
The inspection task name. |
codeup-demo test inspection |
|
isRequired |
boolean |
body |
No |
Enable the requirement for automated status checks before merging. |
true |
Request examples
Central edition
curl -X 'POST' \
'https://{domain}/oapi/v1/codeup/organizations/60d54f3daccf2bbd6659f3ad/repositories/2813489%E6%88%96%E8%80%8560de7a6852743a5162b5f957%2FDemoRepo/protectedBranches' \
-H 'Content-Type: application/json' \
-H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484' \
--data '
{
"allowMergeRoles": [40, 30],
"allowMergeUserIds": ["62c795xxxb468af8"],
"allowPushRoles": [40, 30],
"allowPushUserIds": ["62c795xxxb468af8"],
"branch": "master",
"mergeRequestSetting": {
"allowMergeRequestRoles": [40, 30],
"defaultAssignees": ["62c795xxxb468af8"],
"isAllowSelfApproval": false,
"isAllowSourceBranchPushUserApproval": false,
"isRequireDiscussionProcessed": true,
"isRequired": true,
"isResetApprovalWhenNewPush": true,
"minimumApproval": 1,
"mrMode": "general",
"whiteList": "*.java"
},
"testSetting": {
"checkCheckRunConfig": {
"checkRunCheckItems": [
{
"id": "62c795xxxb468af8",
"name": "default-test-check-run-name",
"required": true,
"type": "User"
}
]
},
"checkCommitStatusConfig": {
"commitStatusCheckItems": [
{
"context": "default-context",
"required": true
}
]
},
"checkConfig": {
"checkItems": [
{
"isRequired": true,
"pipelineId": 1880578,
"pipelineName": "Test code inspection"
}
]
},
"checkTaskQualityConfig": {
"bizNo": "202207270957450000110900090430096",
"enabled": true,
"message": "codeup-demo test code inspection task",
"taskName": "codeup-demo test inspection"
},
"isRequired": true
}
}'
Region edition
curl -X 'POST' \
'https://{domain}/oapi/v1/codeup/repositories/2813489或者60de7a6852743a5162b5f957%2FDemoRepo/protectedBranches' \
-H 'Content-Type: application/json' \
-H 'x-yunxiao-token: pt-0fh3****0fbG_35af****0484' \
--data '
{
"allowMergeRoles": [40, 30],
"allowMergeUserIds": ["62c795xxxb468af8"],
"allowPushRoles": [40, 30],
"allowPushUserIds": ["62c795xxxb468af8"],
"branch": "master",
"mergeRequestSetting": {
"allowMergeRequestRoles": [40, 30],
"defaultAssignees": ["62c795xxxb468af8"],
"isAllowSelfApproval": false,
"isAllowSourceBranchPushUserApproval": false,
"isRequireDiscussionProcessed": true,
"isRequired": true,
"isResetApprovalWhenNewPush": true,
"minimumApproval": 1,
"mrMode": "general",
"whiteList": "*.java"
},
"testSetting": {
"checkCheckRunConfig": {
"checkRunCheckItems": [
{
"id": "62c795xxxb468af8",
"name": "default-test-check-run-name",
"required": true,
"type": "User"
}
]
},
"checkCommitStatusConfig": {
"commitStatusCheckItems": [
{
"context": "default-context",
"required": true
}
]
},
"checkConfig": {
"checkItems": [
{
"isRequired": true,
"pipelineId": 1880578,
"pipelineName": "Test code inspection"
}
]
},
"checkTaskQualityConfig": {
"bizNo": "202207270957450000110900090430096",
"enabled": true,
"message": "codeup-demo test code inspection task",
"taskName": "codeup-demo test inspection"
},
"isRequired": true
}
}'
Response parameters
|
Parameter |
Type |
Description |
Example value |
| - |
object |
||
|
allowMergeRoles |
array[integer] |
The list of roles allowed to merge changes: 40 for administrators and 30 for developers. |
[40, 30] |
|
allowMergeUserIds |
array[string] |
The list of user IDs allowed to merge changes. |
["62c795xxxb468af8"] |
| allowMergeUsers |
array |
The list of users allowed to merge changes. |
|
| - |
object |
||
|
avatarUrl |
string |
The profile picture URL. |
https://example/example/w/100/h/100 |
|
|
string |
The email address. |
username@example.com |
|
id |
integer |
The database primary key ID. This ID has no business meaning. |
1 |
|
name |
string |
The user name. |
codeup-demo |
|
userId |
string |
The Apsara DevOps user ID. Use this ID wherever a user ID is required in the Codeup OpenAPI. |
62c795xxxb468af8 |
|
username |
string |
The user name (logon name). |
codeup-username |
|
allowPushRoles |
array[integer] |
The list of roles allowed to push changes: 40 for administrators and 30 for developers. |
[40, 30] |
|
allowPushUserIds |
array[string] |
The list of user IDs allowed to push changes. |
["62c795xxxb468af8"] |
| allowPushUsers |
array |
The list of users allowed to push changes. |
|
| - |
object |
||
|
avatarUrl |
string |
The profile picture URL. |
https://example/example/w/100/h/100 |
|
|
string |
The email address. |
username@example.com |
|
id |
integer |
The database primary key ID. This ID has no business meaning. |
1 |
|
name |
string |
The user name. |
codeup-demo |
|
userId |
string |
The Apsara DevOps user ID. Use this ID wherever a user ID is required in the Codeup OpenAPI. |
62c795xxxb468af8 |
|
username |
string |
The user name (logon name). |
codeup-username |
|
branch |
string |
The branch name. |
master |
|
createdAt |
string |
The creation time. |
2024-10-05T15:30:45Z |
|
id |
integer |
The protected branch rule ID. |
1 |
|
matches |
array[string] |
The list of matched branches. |
["master"] |
| mergeRequestSetting |
object |
||
|
allowMergeRequestRoles |
array[integer] |
The list of roles allowed to submit merge requests. |
[40, 30] |
| defaultAssignees |
array |
The list of default reviewers. |
|
| - |
object |
||
|
avatarUrl |
string |
The profile picture URL. |
https://example/example/w/100/h/100 |
|
|
string |
The email address. |
username@example.com |
|
id |
integer |
The database primary key ID. This ID has no business meaning. |
1 |
|
name |
string |
The user name. |
codeup-demo |
|
userId |
string |
The Apsara DevOps user ID. Use this ID wherever a user ID is required in the Codeup OpenAPI. |
62c795xxxb468af8 |
|
username |
string |
The user name (logon name). |
codeup-username |
|
isAllowSelfApproval |
boolean |
Whether to allow creators to perform code reviews. |
false |
|
isAllowSourceBranchPushUserApproval |
boolean |
Allow the committer from the source branch to approve the merge request. |
false |
|
isRequireDiscussionProcessed |
boolean |
Is review of all resolved items required? |
true |
|
isRequired |
boolean |
Enable |
true |
|
isResetApprovalWhenNewPush |
boolean |
Reset the approval status when new commits are pushed. |
true |
|
minimumApproval |
integer |
The minimum number of approvals required. This setting applies only in general mode. |
1 |
|
mrMode |
string |
Review mode: General (standard mode) or CodeOwner (CodeOwner mode). |
general |
|
whiteList |
string |
The file whitelist for code review. Enter file paths, separated by line feeds. Use English-style wildcard characters. |
*.java |
| testSetting |
object |
||
| checkCheckRunConfig |
object |
Run checks. |
|
| checkRunCheckItems |
array |
The list of configuration items. |
|
| - |
object |
||
|
id |
string |
The ID of the person who created the check run. |
62c795xxxb468af8 |
|
name |
string |
The name of the check run. |
default-test-check-run-name |
|
required |
boolean |
Is this a checkpoint? |
true |
|
type |
string |
The type of the person who created the check run: User. |
User |
| checkCommitStatusConfig |
object |
Commit status. |
|
| commitStatusCheckItems |
array |
The list of configuration items. |
|
| - |
object |
||
|
context |
string |
The name of the third-party commit status. This name is used as the matching item for gatekeeper checks. |
default-context |
|
required |
boolean |
Treat this as a gatekeeper check. |
true |
| checkConfig |
object |
Pipeline checks. |
|
| checkItems |
array |
The list of configuration items. |
|
| - |
object |
||
|
isRequired |
boolean |
This is a gatekeeper check. |
true |
|
pipelineId |
integer |
The pipeline ID. |
1880578 |
|
pipelineName |
string |
The pipeline name. |
codeup-demo test code inspection |
| checkTaskQualityConfig |
object |
Code inspection task. |
|
|
bizNo |
string |
The pipeline number of the inspection task. |
202207192301340000110700070550024 |
|
enabled |
boolean |
Enable this setting. |
true |
|
message |
string |
A description. |
Test code inspection |
|
taskName |
string |
The inspection task name. |
codeup-demo code inspection |
|
isRequired |
boolean |
Enable this setting. |
true |
|
updatedAt |
string |
The update time. |
2024-10-05T15:30:45Z |
Response example
{
"allowMergeRoles": [40, 30],
"allowMergeUserIds": ["62c795xxxb468af8"],
"allowMergeUsers": [
{
"avatarUrl": "https://example/example/w/100/h/100",
"email": "username@example.com",
"id": 1,
"name": "codeup-demo",
"userId": "62c795xxxb468af8",
"username": "codeup-username"
}
],
"allowPushRoles": [40, 30],
"allowPushUserIds": ["62c795xxxb468af8"],
"allowPushUsers": [
{
"avatarUrl": "https://example/example/w/100/h/100",
"email": "username@example.com",
"id": 1,
"name": "codeup-demo",
"userId": "62c795xxxb468af8",
"username": "codeup-username"
}
],
"branch": "master",
"createdAt": "2024-10-05T15:30:45Z",
"id": 1,
"matches": ["master"],
"mergeRequestSetting": {
"allowMergeRequestRoles": [40, 30],
"defaultAssignees": [
{
"avatarUrl": "https://example/example/w/100/h/100",
"email": "username@example.com",
"id": 1,
"name": "codeup-demo",
"userId": "62c795xxxb468af8",
"username": "codeup-username"
}
],
"isAllowSelfApproval": false,
"isAllowSourceBranchPushUserApproval": false,
"isRequireDiscussionProcessed": true,
"isRequired": true,
"isResetApprovalWhenNewPush": true,
"minimumApproval": 1,
"mrMode": "general",
"whiteList": "*.java"
},
"testSetting": {
"checkCheckRunConfig": {
"checkRunCheckItems": [
{
"id": "62c795xxxb468af8",
"name": "default-test-check-run-name",
"required": true,
"type": "User"
}
]
},
"checkCommitStatusConfig": {
"commitStatusCheckItems": [
{
"context": "default-context",
"required": true
}
]
},
"checkConfig": {
"checkItems": [
{
"isRequired": true,
"pipelineId": 1880578,
"pipelineName": "codeup-demo test code inspection"
}
]
},
"checkTaskQualityConfig": {
"bizNo": "202207192301340000110700070550024",
"enabled": true,
"message": "Test code inspection",
"taskName": "codeup-demo code inspection"
},
"isRequired": true
},
"updatedAt": "2024-10-05T15:30:45Z"
}
Error codes
For more information, see the error code center.