Create a protected branch rule¶
PUT /api/v5/repos/{owner}/{repo}/branches/setting/new
Creates a protected branch rule for the specified repository. By setting a branch or wildcard and specifying the member roles that may push code and merge pull requests, it controls who may change code on that branch.
Supported access tokens¶
- AtomGit user access tokens
Anonymous access allowed¶
This endpoint does not allow anonymous access.
Request parameters¶
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
owner |
path | string | Yes | Namespace address to which the repository belongs (address path of the organization or user) |
repo |
path | string | Yes | Repository path (path) |
access_token |
query | string | Yes | User authorization code |
Request Body:
The request body is a JSON object that specifies the branches the protection rule matches and the member push/merge permissions.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"wildcard": {
"description": "Branch/wildcard",
"type": "string"
},
"pusher": {
"description": "Members who may push code. develop: repository administrators and developers; admin: repository administrators; maintainer: maintainers; separate multiple roles with a semicolon. To specify users, pass their usernames separated by semicolons. Empty string: nobody may push",
"type": "string"
},
"merger": {
"description": "Members who may merge pull requests. develop: repository administrators and developers; admin: repository administrators; maintainer: maintainers; separate multiple roles with a semicolon. To specify users, pass their usernames separated by semicolons. Empty string: nobody may merge",
"type": "string"
}
},
"required": ["wildcard", "pusher", "merger"]
}
Response parameters¶
On success this endpoint returns an empty JSON object {} with no other response fields.
Error response¶
The reference documentation only describes the 200 success response and provides no error response examples; error field names on failure follow what the backend actually returns.
HTTP status codes¶
| Status code | Description |
|---|---|
200 |
Success (OK) |
401 |
Authentication required (Requires authentication) |
403 |
Access forbidden (Forbidden) |
404 |
Resource does not exist (Not found) |
429 |
Too many requests (Rate limited) |
500 |
Internal system error (Internal server error) |
Request example¶
Parameter notes¶
Replace
<owner>with the namespace address to which the repository belongs (the address path of the enterprise, organization, or user); replace<repo>with the repository path (path); replace<token>with your AtomGit user access token.
cURL¶
curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/setting/new?access_token=<token>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"wildcard": "master",
"pusher": "develop",
"merger": "develop"
}'
JavaScript¶
// Native fetch (Node.js 18+ / browsers)
const response = await fetch(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/setting/new?access_token=<token>",
{
method: "PUT",
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
wildcard: "master",
pusher: "develop",
merger: "develop"
})
}
);
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.put(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/setting/new",
params={"access_token": "<token>"},
json={
"wildcard": "master",
"pusher": "develop",
"merger": "develop"
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
Response example¶
Status code: 200
Error codes¶
| Error code | Description |
|---|---|
401 |
Unauthenticated or invalid credentials (missing or invalid access credentials) |
403 |
No permission to perform this operation |
404 |
Repository or endpoint path does not exist |
405 |
Request method not supported |
429 |
Too many requests; rate limit triggered |
500 |
Internal system error |
Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc