GetProtectedBranch - Query a protected branch

Updated at:

Queries the configuration of a single protected branch, including merge and push permissions, review settings, and test checks.

Applicable editions

Central edition, Region edition

Endpoint and authorization information

  • Obtain the endpoint: Replace {domain} in the API request syntax.

  • Obtain a personal access token.

  • Obtain the organizationId: Required only for the Central edition. Go to the Basic Information page in the Organization Management Console to obtain the organization ID.

Product

Resource

Required permission

Code Management

Protected branch

Read-only

Request syntax

Central edition

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

Region edition

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

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

  • Yes: Central edition

  • No: Region edition

The organization ID.

60d54f3daccf2bbd6659f3ad

repositoryId

integer

path

Yes

The repository ID or the full path URL-encoded.

2813489 or 60de7a6852743a5162b5f957%2FDemoRepo

id

integer

path

Yes

The primary key ID of the protected branch rule.

1

Request examples

Central edition

curl -X 'GET' \
  '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'

Region edition

curl -X 'GET' \
  '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'

Response parameters

Parameter

Type

Description

Example value

-

object

allowMergeRoles

array[integer]

The list of roles allowed to merge changes. Valid values: 40 (administrator) and 30 (developer).

[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

email

string

The email address.

username@example.com

id

integer

The internal primary key ID. Not used in business logic.

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. Valid values: 40 (administrator) and 30 (developer).

[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

email

string

The email address.

username@example.com

id

integer

The internal primary key ID. Not used in business logic.

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 matching branches.

["master"]

mergeRequestSetting

object

allowMergeRequestRoles

array[integer]

The list of roles allowed to approve 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

email

string

The email address.

username@example.com

id

integer

The internal primary key ID. Not used in business logic.

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 the author can approve their own code review.

false

isAllowSourceBranchPushUserApproval

boolean

Whether contributors from the source branch can approve merge requests.

false

isRequireDiscussionProcessed

boolean

Whether all discussions must be resolved before merging.

true

isRequired

boolean

Whether merge request review is enabled.

true

isResetApprovalWhenNewPush

boolean

Whether to reset the approval status when new changes are pushed.

true

minimumApproval

integer

The minimum number of approvers required. This setting applies only in standard mode.

1

mrMode

string

The review mode. Valid values: general (standard mode) and codeowner (CodeOwner mode).

general

whiteList

string

The file path whitelist for reviews. Separate multiple paths with line breaks. Wildcard characters are supported.

*.java

testSetting

object

checkCheckRunConfig

object

The check run configuration.

checkRunCheckItems

array

The list of configuration items.

-

object

id

string

The author ID.

62c795xxxb468af8

name

string

The name of the check run.

default-test-check-run-name

required

boolean

Whether this check run is required as a gate check.

true

type

string

The check run type. Valid value: User.

User

checkCommitStatusConfig

object

The commit status check configuration.

commitStatusCheckItems

array

The list of configuration items.

-

object

context

string

The name of the third-party commit status. This name is used as the match condition for gatekeepers.

default-context

required

boolean

Whether this commit status check is required.

true

checkConfig

object

The CI pipeline check configuration.

checkItems

array

The list of configuration items.

-

object

isRequired

boolean

Whether this pipeline check is required.

true

pipelineId

integer

The CI pipeline ID.

1880578

pipelineName

string

The CI pipeline name.

codeup-demo test code inspection

checkTaskQualityConfig

object

The code inspection task.

bizNo

string

The pipeline number of the inspection task.

202207192301340000110700070550024

enabled

boolean

Whether the inspection task is enabled.

true

message

string

The description.

Test code inspection

taskName

string

The name of the inspection task.

codeup-demo code inspection

isRequired

boolean

Whether the inspection task is enabled.

true

updatedAt

string

The last 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 Error code center.