Fork repository¶
POST /api/v5/repos/{owner}/{repo}/forks
This endpoint copies (forks) the specified repository to a target namespace. You can specify an organization namespace, a new repository name, and a new path. If not specified, the repository is copied to the user's personal namespace by default, retaining the source repository's name and address. On success, the full information of the new repository is returned.
Access token support¶
- AtomGit user 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 | Address path of the namespace the repository belongs to (the address path of an enterprise, organization, or individual) |
repo |
path | string | Yes | Repository path (path) |
access_token |
query | string | Yes | User authorization code |
Request Body:
The request body is in application/json format. All of the following fields are optional; default values are used when they are omitted:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"organization": {
"description": "Full address of the organization namespace. If omitted, the repository is forked to the user's personal namespace address by default",
"type": "string"
},
"name": {
"description": "Repository name after forking. Default: source repository name",
"type": "string"
},
"path": {
"description": "Repository address after forking. Default: source repository address",
"type": "string"
}
}
}
Response parameters¶
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
id |
integer | Yes | No | Repository ID |
full_name |
string | Yes | No | Full repository name (namespace/repository name), e.g. xiaogang_test/fork2 |
human_name |
string | Yes | No | Repository display name, e.g. Test organization / fork2 |
url |
string | Yes | No | Repository API address |
namespace |
object | Yes | No | Information about the namespace the repository belongs to (enterprise, organization, or individual) |
namespace object
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
namespace.id |
integer | Yes | No | Namespace ID |
namespace.name |
string | Yes | No | Namespace name |
namespace.path |
string | Yes | No | Namespace address path |
namespace.develop_mode |
string | Yes | No | Development mode |
namespace.cell |
string | Yes | No | Namespace cell |
namespace.kind |
string | Yes | No | Namespace type, e.g. group |
namespace.full_path |
string | Yes | No | Full namespace path |
namespace.full_name |
string | Yes | No | Full namespace name |
namespace.visibility_level |
integer | Yes | No | Visibility level |
namespace.enable_file_control |
integer | Yes | No | Whether file control is enabled |
Error response¶
The following are examples of common error responses. The actual error field names are subject to what the backend returns.
400 Parameter error
401 Unauthenticated
HTTP response status codes¶
| Status code | Description |
|---|---|
200 |
Success (OK) |
400 |
Parameter error (Bad request) |
401 |
Authentication required (Requires authentication) |
403 |
Forbidden |
404 |
Request path does not exist (Not found) |
Request example¶
Parameter description¶
Placeholder description in the example:
Replace
<owner>with the address path of the namespace the repository belongs to (the address path of an enterprise, organization, or individual); replace<repo>with the repository path (path); replace<token>with your AtomGit user access token;<org_path>,<new_name>, and<new_path>are optional request body fields; default values are used when they are not passed.
cURL¶
curl -X POST 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/forks?access_token=<token>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"organization": "<org_path>",
"name": "<new_name>",
"path": "<new_path>"
}'
JavaScript¶
// Native fetch (Node.js 18+ / browser)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/forks?access_token=<token>", {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
organization: "<org_path>",
name: "<new_name>",
path: "<new_path>",
}),
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.post(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/forks",
params={"access_token": "<token>"},
headers={
"Accept": "application/json",
"Content-Type": "application/json",
},
json={
"organization": "<org_path>",
"name": "<new_name>",
"path": "<new_path>",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
Response example¶
Status code: 200
{
"id": 729292,
"full_name": "xiaogang_test/fork2",
"human_name": "Test organization / fork2",
"url": "https://api.atomgit.com/api/v5/repos/xiaogang_test/fork2",
"namespace": {
"id": 138108,
"name": "Test organization",
"path": "xiaogang_test",
"develop_mode": "normal",
"cell": "default",
"kind": "group",
"full_path": "xiaogang_test",
"full_name": "Test organization",
"visibility_level": 20,
"enable_file_control": false
}
}
Error codes¶
| Error code | Description |
|---|---|
400 |
Parameter error or the request cannot be parsed |
401 |
Unauthenticated or invalid credentials |
403 |
Forbidden |
404 |
Request path does not exist |
500 |
Internal system error |
Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc