UpdateProtectedBranch - Update Protected Branch

Updated at:

Updates the settings of a protected branch, including merge and push permissions, code review requirements, and automated status checks.

Applicable editions

Central edition, Region edition

Endpoints and Authorization Information

Product

Resource

Required Permissions

Code Management

Protected Branch

Read/Write

Request Syntax

Central edition

PUT https://{domain}/oapi/v1/codeup/organizations/{organizationId}/repositories/{repositoryId}/protectedBranches/{id}

Region edition

PUT https://{domain}/oapi/v1/codeup/repositories/{repositoryId}/protectedBranches/{id}

Request Headers

Parameter

Type

Required

Description

Example Value

x-yunxiao-token

string

Yes

Personal access token.

pt-0fh3****0fbG_35af****0484

Request Parameters

Parameter

Type

Location

Required

Description

Example Value

organizationId

string

path

  • Yes: Central edition

  • No: Region edition

Organization ID.

60d54f3daccf2bbd6659f3ad

repositoryId

string

path

Yes

Repository ID or URL-encoded full path.

2813489 or 60de7a6852743a5162b5f957%2FDemoRepo

id

integer

path

Yes

Primary key ID of the protected branch rule.

1

-

object

body

No

allowMergeRoles

array[integer]

body

No

List of roles allowed to merge: 40 for administrator, 30 for developer.

[40, 30]

allowMergeUserIds

array[string]

body

No

List of user IDs allowed to merge.

["62c795xxxb468af8"]

allowPushRoles

array[integer]

body

No

List of roles allowed to push: 40 for administrator, 30 for developer.

[40, 30]

allowPushUserIds

array[string]

body

No

List of user IDs allowed to push.

["62c795xxxb468af8"]

branch

string

body

Yes

Name of the protected branch.

master

mergeRequestSetting

object

body

No

Code review settings for merge requests.

allowMergeRequestRoles

array[integer]

body

No

List of roles allowed to merge requests.

[40, 30]

defaultAssignees

array[string]

body

No

List of default reviewer IDs.

["62c795xxxb468af8"]

isAllowSelfApproval

boolean

body

No

Whether the author can approve their own code review.

false

isAllowSourceBranchPushUserApproval

boolean

body

No

Allow source branch committers to approve merge requests.

false

isRequireDiscussionProcessed

boolean

body

No

Whether all discussions must be resolved before merging.

true

isRequired

boolean

body

No

Enable "Require code review before merging".

true

isResetApprovalWhenNewPush

boolean

body

No

Reset approval status when new pushes occur.

true

minimumApproval

integer

body

No

Minimum number of approvals required. This applies only to NAT mode.

1

mrMode

string

body

No

Review mode. Valid values: general and CodeOwner.

general

whiteList

string

body

No

Review file allowlist. Specify file paths separated by newlines. Wildcard characters are supported.

*.java

testSetting

object

body

No

Automated status check settings for merge requests.

checkCheckRunConfig

object

body

No

Check run configuration.

checkRunCheckItems

array

body

No

List of configuration items.

-

object

body

No

id

string

body

No

Writer's ID.

62c795xxxb468af8

name

string

body

No

Name of the check run.

default-test-check-run-name

required

boolean

body

No

Whether to use as a required check.

true

type

string

body

No

Writer type: User.

User

checkCommitStatusConfig

object

body

No

Commit status.

commitStatusCheckItems

array

body

No

List of configuration items.

-

object

body

No

context

string

body

No

Name of the third-party commit status, used as the identifier for the required check.

default-context

required

boolean

body

No

Whether to use as a required check.

true

checkConfig

object

body

No

Pipeline check configuration.

checkItems

array

body

No

List of configuration items.

-

object

body

No

isRequired

boolean

body

No

Whether this is a required check.

true

pipelineId

integer

body

No

Pipeline ID.

1880578

pipelineName

string

body

No

Pipeline name.

Test code scanning

checkTaskQualityConfig

object

body

No

Code scanning task configuration.

bizNo

string

body

No

Detection task pipeline number.

202207270957450000110900090430096

enabled

boolean

body

No

Whether to enable code scanning.

true

message

string

body

No

Description.

codeup-demo test code scanning task

taskName

string

body

No

Detection task name.

codeup-demo test scan

isRequired

boolean

body

No

Whether automated status checks are required before merging.

true

Request Examples

Central edition

curl -X 'PUT' \
  'https://{domain}/oapi/v1/codeup/organizations/60d54f3daccf2bbd6659f3ad/repositories/2813489 or 60de7a6852743a5162b5f957%2FDemoRepo/protectedBranches/1' \
  -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 detection"
                    }
                ]
            },
            "checkTaskQualityConfig": {
                "bizNo": "202207270957450000110900090430096",
                "enabled": true,
                "message": "codeup-demo test code detection task",
                "taskName": "codeup-demo test detection"
            },
            "isRequired": true
        }
    }'

Region edition

curl -X 'PUT' \
  'https://{domain}/oapi/v1/codeup/repositories/2813489 or 60de7a6852743a5162b5f957%2FDemoRepo/protectedBranches/1' \
  -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 detection"
                    }
                ]
            },
            "checkTaskQualityConfig": {
                "bizNo": "202207270957450000110900090430096",
                "enabled": true,
                "message": "codeup-demo test code detection task",
                "taskName": "codeup-demo test detection"
            },
            "isRequired": true
        }
    }'

Response Parameters

Parameter

Type

Description

Example Value

-

object

allowMergeRoles

array[integer]

List of roles allowed to merge: 40 for administrator, 30 for developer.

[40, 30]

allowMergeUserIds

array[string]

List of user IDs allowed to merge.

["62c795xxxb468af8"]

allowMergeUsers

array

List of users allowed to merge.

-

object

avatarUrl

string

Profile picture URL.

https://example/example/w/100/h/100

email

string

Email address.

username@example.com

id

integer

Database primary key ID (no business meaning).

1

name

string

User name.

codeup-demo

userId

string

Apsara Devops user ID. Use this ID for all user ID references in Codeup OpenAPI.

62c795xxxb468af8

username

string

Username (login name).

codeup-username

allowPushRoles

array[integer]

List of roles allowed to push: 40 for administrator, 30 for developer.

[40, 30]

allowPushUserIds

array[string]

List of user IDs allowed to push.

["62c795xxxb468af8"]

allowPushUsers

array

List of users allowed to push.

-

object

avatarUrl

string

Profile picture URL.

https://example/example/w/100/h/100

email

string

Email address.

username@example.com

id

integer

Database primary key ID (no business meaning).

1

name

string

User name.

codeup-demo

userId

string

Apsara Devops user ID. Use this ID for all user ID references in Codeup OpenAPI.

62c795xxxb468af8

username

string

Username (login name).

codeup-username

branch

string

Branch name.

master

createdAt

string

Creation time.

2024-10-05T15:30:45Z

id

integer

Protected branch rule ID.

1

matches

array[string]

List of matching branches.

["master"]

mergeRequestSetting

object

allowMergeRequestRoles

array[integer]

List of roles allowed to merge requests.

[40, 30]

defaultAssignees

array

List of default reviewers.

-

object

avatarUrl

string

Profile picture URL.

https://example/example/w/100/h/100

email

string

Email address.

username@example.com

id

integer

Database primary key ID (no business meaning).

1

name

string

User name.

codeup-demo

userId

string

Apsara Devops user ID. Use this ID for all user ID references in Codeup OpenAPI.

62c795xxxb468af8

username

string

Username (login name).

codeup-username

isAllowSelfApproval

boolean

Whether the author can approve their own code review.

false

isAllowSourceBranchPushUserApproval

boolean

Whether source branch committers can approve merge requests.

false

isRequireDiscussionProcessed

boolean

Whether all discussions must be resolved before merging.

true

isRequired

boolean

Whether code review is required.

true

isResetApprovalWhenNewPush

boolean

Reset approval status when new pushes occur.

true

minimumApproval

integer

Minimum number of approvals required. This applies only to NAT mode.

1

mrMode

string

Review mode. Valid values: General and CodeOwner.

general

whiteList

string

Review file allowlist. Specify file paths separated by newlines. Wildcard characters are supported.

*.java

testSetting

object

checkCheckRunConfig

object

Check run configuration.

checkRunCheckItems

array

List of configuration items.

-

object

id

string

Writer's ID.

62c795xxxb468af8

name

string

Name of the check run.

default-test-check-run-name

required

boolean

Whether to use as a required check.

true

type

string

Writer type: User.

User

checkCommitStatusConfig

object

Commit status.

commitStatusCheckItems

array

List of configuration items.

-

object

context

string

Name of the third-party commit status, used as the identifier for the required check.

default-context

required

boolean

Whether to use as a required check.

true

checkConfig

object

Pipeline check configuration.

checkItems

array

List of configuration items.

-

object

isRequired

boolean

Whether this is a required check.

true

pipelineId

integer

Pipeline ID.

1880578

pipelineName

string

Pipeline name.

codeup-demo Test Code Detection

checkTaskQualityConfig

object

Code scanning task configuration.

bizNo

string

Detection task pipeline number.

202207192301340000110700070550024

enabled

boolean

Whether code scanning is enabled.

true

message

string

Description.

Test code detection

taskName

string

Detection task name.

codeup-demo Code Detection

isRequired

boolean

Whether automated status checks are required before merging.

true

updatedAt

string

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 Detection"
                }
            ]
        },
        "checkTaskQualityConfig": {
            "bizNo": "202207192301340000110700070550024",
            "enabled": true,
            "message": "Test code detection",
            "taskName": "codeup-demo Code Detection"
        },
        "isRequired": true
    },
    "updatedAt": "2024-10-05T15:30:45Z"
}

Error Codes

For API error codes, see Error Code Center.