CreateProtectdBranch

Updated at:

Creates a protected branch for a code repository.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

No authorization for this operation. If you encounter issues with this operation, contact technical support.

Request syntax

POST /repository/{repositoryId}/protect_branches HTTP/1.1

Path Parameters

Parameter

Type

Required

Description

Example

repositoryId

integer

Yes

The code repository ID.

2813891

Request parameters

Parameter

Type

Required

Description

Example

organizationId

string

Yes

The enterprise identifier, also known as the enterprise ID. This string can be obtained from the Yunxiao URL, such as https://devops.aliyun.com/organization/[OrganizationId].

60de7a6852743a5162b5f957

accessToken

string

No

The personal access token. This field is not required if you use an Alibaba Cloud AccessKey ID and AccessKey secret or Security Token Service (STS) temporary authorization.

f0b1e61db5961df5975a93f9129d2513

body

object

Yes

The request body.

id

integer

No

The ID of the protected branch rule.

1

branch

string

Yes

The name of the protected branch.

protectBranch

allowPushRoles

array

No

The list of roles that are allowed to push.

integer

No

Valid values:

  • 40: Administrator.

  • 30: Developer.

40

allowPushUserIds

array

No

The IDs of the users who are allowed to push.

string

No

The Alibaba Cloud account ID.

2344667212345561

allowMergeRoles

array

Yes

The list of roles that are allowed to merge.

integer

Yes

Valid values:

  • 40: Administrator.

  • 30: Developer.

40

allowMergeUserIds

array

No

The IDs of the users who are allowed to merge.

string

No

The Alibaba Cloud account ID.

123345678912345

mergeRequestSetting

object

No

The code review settings before merging.

isRequired

boolean

No

Specifies whether to enable code review.

true

mrMode

string

No

The review mode. Valid values:

  • general: standard

  • codeowner: CodeOwner mode

general

isAllowSelfApproval

boolean

No

Specifies whether to allow the creator to approve the code review.

true

isRequireDiscussionProcessed

boolean

No

Specifies whether all comments must be resolved.

true

isResetApprovalWhenNewPush

boolean

No

Specifies whether to reset the review when a new commit is pushed.

false

minimumApproval

integer

No

The minimum number of approvers required to pass the review. This parameter takes effect only in standard mode.

1

allowMergeRequestRoles

array

No

The list of roles that are allowed to merge.

integer

No

Valid values:

  • 40: Administrator (default).

  • 30: Developer.

40

defaultAssignees

array

No

The default reviewers.

string

No

The Alibaba Cloud account ID.

1234567891234567

whiteList

string

No

The whitelist of files for code review.

Important Files added to the whitelist are exempt from the minimum number of approvers requirement and do not require mandatory manual review.

**.java

testSettingDTO

object

No

The automated status check settings before merging.

isRequired

boolean

No

Specifies whether to enable code review.

false

codeGuidelinesDetection

object

No

The code guideline scanning.

enabled

boolean

No

Specifies whether to enable code review.

false

message

string

No

The description.

test_code_guide_lines

sensitiveInfoDetection

object

No

The sensitive information scanning.

enabled

boolean

No

Specifies whether to enable code review.

false

message

string

No

The description.

test_code_sensitive_info

checkTaskQualityConfig

object

No

The code quality check.

enabled

boolean

No

Specifies whether to enable code review.

false

bizNo

string

No

The task serial number.

123456

taskName

string

No

The task name.

bz-task-quality

message

string

No

The message.

test_task_quality

checkConfig

object

No

The pipeline configuration for merge request gates.

checkItems

array<object>

No

The configuration items.

object

No

The configuration items.

name

string

No

The pipeline name.

Test pipeline

isRequired

boolean

No

Specifies whether to set this item as a gate check.

false

Response elements

Element

Type

Description

Example

object

Schema of Response

requestId

string

The request ID.

C2F153F6-BB43-50C4-9F4F-40593203E19A

errorMessage

string

The error message.

""

errorCode

string

The error code.

Openapi.RequestError

success

boolean

Indicates whether the call is successful.

true

result

object

The returned result.

id

integer

The ID of the protected branch rule.

5240

branch

string

The name of the protected branch.

protectBranch

allowPushRoles

array

The list of roles that are allowed to push.

integer

Valid values:

  • 40: Administrator.

  • 30: Developer.

40

allowPushUserIds

array

The list of user IDs allowed to push.

integer

The Codeup user ID.

19238

allowMergeRoles

array

The list of roles that are allowed to merge.

integer

Valid values:

  • 40: Administrator.

  • 30: Developer.

40

allowMergeUserIds

array

The IDs of the users who are allowed to merge.

integer

The Codeup user ID.

19238

mergeRequestSetting

object

The code review settings before merging.

isRequired

boolean

Specifies whether to enable code review.

true

mrMode

string

The review mode. Valid values:

  • general: Standard.

  • codeowner: CodeOwner mode.

general

isAllowSelfApproval

boolean

Specifies whether to allow the creator to approve the code review.

true

isRequireDiscussionProcessed

boolean

Specifies whether all review discussions must be resolved.

true

isResetApprovalWhenNewPush

boolean

Specifies whether to reset the review when a new commit is pushed.

false

minimumApproval

integer

The minimum number of approvals required to pass a review. Note: This parameter takes effect only in standard mode.

1

allowMergeRequestRoles

array

The list of roles allowed to merge requests.

integer

Valid values:

  • 40: Administrator (default).

  • 30: Developer.

40

defaultAssignees

array

The IDs of the default reviewers.

string

The Yunxiao user ID.

5f969843cd2214ba0e24327d

whiteList

string

The whitelist of files for review. Note: Files added to the whitelist are exempt from the minimum number of approvals requirement and do not require mandatory manual review.

**.java

testSettingDTO

object

The automated status check settings before merging.

isRequired

boolean

Specifies whether to enable code review.

false

codeGuidelinesDetection

object

The code guideline scanning.

enabled

boolean

Specifies whether to enable code review.

false

message

string

The description.

test_code_guide_lines

sensitiveInfoDetection

object

The sensitive information scanning.

enabled

boolean

Specifies whether to enable code review.

false

message

string

The description.

test_code_sensitive_info

checkTaskQualityConfig

object

The code quality check.

enabled

boolean

Specifies whether to enable code review.

false

bizNo

string

The task serial number.

123456

taskName

string

The task name.

biz-task-quality

message

string

The description.

test_task_quality

checkConfig

object

The pipeline configuration for merge request gates.

checkItems

array<object>

The list of configuration items.

object

The configuration items.

name

string

The pipeline name.

Test pipeline

isRequired

boolean

Specifies whether to set this item as a gate check.

false

Examples

Success response

JSON format

{
  "requestId": "C2F153F6-BB43-50C4-9F4F-40593203E19A",
  "errorMessage": "\"\"",
  "errorCode": "Openapi.RequestError",
  "success": true,
  "result": {
    "id": 5240,
    "branch": "protectBranch",
    "allowPushRoles": [
      40
    ],
    "allowPushUserIds": [
      19238
    ],
    "allowMergeRoles": [
      40
    ],
    "allowMergeUserIds": [
      19238
    ],
    "mergeRequestSetting": {
      "isRequired": true,
      "mrMode": "general",
      "isAllowSelfApproval": true,
      "isRequireDiscussionProcessed": true,
      "isResetApprovalWhenNewPush": false,
      "minimumApproval": 1,
      "allowMergeRequestRoles": [
        40
      ],
      "defaultAssignees": [
        "5f969843cd2214ba0e24327d"
      ],
      "whiteList": "**.java"
    },
    "testSettingDTO": {
      "isRequired": false,
      "codeGuidelinesDetection": {
        "enabled": false,
        "message": "test_code_guide_lines"
      },
      "sensitiveInfoDetection": {
        "enabled": false,
        "message": "test_code_sensitive_info"
      },
      "checkTaskQualityConfig": {
        "enabled": false,
        "bizNo": "123456",
        "taskName": "biz-task-quality",
        "message": "test_task_quality"
      },
      "checkConfig": {
        "checkItems": [
          {
            "name": "Test pipeline",
            "isRequired": false
          }
        ]
      }
    }
  }
}

Error codes

HTTP status code

Error code

Error message

Description

403 Forbidden.AccessDenied The user is not authorized to perform the operation. The user is not authorized to perform the operation.
403 Forbidden.UserNotInCurrentOrganization The user is not in the organization and is not authorized to perform the operation.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.