Help Center/ CodeArts Repo/ API Reference/ APIs/ Repository/ Creating a Protection Branch
Updated on 2023-05-06 GMT+08:00

Creating a Protection Branch

Function

Creating a Protection Branch

URI

PUT /v2/repositories/{repository_id}/branch/{branch_name}/protect

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

repository_id

Yes

Integer

Warehouse Primary Key ID

branch_name

Yes

String

Branch name.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies the user token.

It can be obtained by calling an IAM API. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

access_level

Yes

AddProtectAccessLevel object

Creating a Protection Branch Permission

Table 4 AddProtectAccessLevel

Parameter

Mandatory

Type

Description

push_access_level

Yes

Integer

Submission permission. The options are as follows: 0: no one can submit; 30: developers and administrators can submit; 40: administrators can submit.

Enumeration values:

  • 0

  • 30

  • 40

merge_access_level

Yes

Integer

Merge permission. 0: No one can merge. 30: Developers and administrators can merge. 40: Administrators can merge. The merge permission must be greater than or equal to the submit permission.

Enumeration values:

  • 0

  • 30

  • 40

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

error

Error object

Response error.

result

AddProtectResponse object

Result

status

String

Response Status

Table 6 Error

Parameter

Type

Description

code

String

Error Codes

message

String

Error message

Table 7 AddProtectResponse

Parameter

Type

Description

name

String

Branch name.

commit

CommitRepoV2 object

Details

protected

Boolean

Whether to protect DWDM.

developers_can_push

Boolean

Allow Developer to Submit

developers_can_merge

Boolean

Allow Developers to Merge

master_can_push

Boolean

Allow Administrator to Submit

master_can_merge

Boolean

Indicates whether to allow administrators to merge.

no_one_can_push

Boolean

No one is allowed to submit.

no_one_can_merge

Boolean

No one is allowed to merge.

in_an_opened_merge_request

Boolean

Indicates whether a combination request is opened.

Table 8 CommitRepoV2

Parameter

Type

Description

id

String

Submit the corresponding SHA ID.

short_id

String

Submit the corresponding short SHA ID.

created_at

String

Created

title

String

Submit Title

parent_ids

Array of strings

Parent Submission ID

message

String

Details

author_name

String

Author

committer_name

String

Requester

committed_date

String

Submitted

Example Requests

PUT https://{endpoint}/v2/repositories/{repository_id}/branch/{branch_name}/protect

{
  "access_level" : {
    "push_access_level" : 40,
    "merge_access_level" : 40
  }
}

Example Responses

Status code: 200

OK

{
  "result" : {
    "name" : "master",
    "commit" : {
      "id" : "3b68902cf0eb7de3d5c8757e4a990bc3fe0af349",
      "short_id" : "3b68902c",
      "title" : "Creating a File",
      "created_at" : "2022-03-08T03:14:39.000Z",
      "parent_ids" : [ "08618c900a4048aae7e4cd88913d3d521eae02eb" ],
      "message" : "Creating a File",
      "author_name" : "repo",
      "committer_name" : "repo",
      "committed_date" : "2022-03-08T03:14:39.000Z"
    },
    "protected" : true,
    "developers_can_push" : false,
    "developers_can_merge" : false,
    "master_can_push" : false,
    "master_can_merge" : false,
    "no_one_can_push" : true,
    "no_one_can_merge" : true,
    "in_an_opened_merge_request" : false
  },
  "status" : "success"
}

Status Codes

Status Code

Description

200

OK

Error Codes

See Error Codes.