创建个人项目仓库¶
POST /api/v5/user/repos
用户调用此接口,进行创建个人项目仓库操作。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
access_token |
query | string | 是 | 用户授权码 |
Request Body:
请求体为 JSON 格式,字段说明如下:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": {
"description": "仓库名称",
"type": "string"
},
"description": {
"description": "仓库描述",
"type": "string"
},
"has_issues": {
"description": "允许提 Issue 与否。默认:允许(true)",
"type": "boolean",
"default": true
},
"has_wiki": {
"description": "提供 Wiki 与否。默认:提供(true)",
"type": "boolean",
"default": true
},
"can_comment": {
"description": "允许用户对仓库进行评论。默认:允许(true)",
"type": "boolean",
"default": true
},
"auto_init": {
"description": "值为 true 时用 README 初始化仓库。默认:不初始化(false)",
"type": "boolean",
"default": false
},
"gitignore_template": {
"description": "Git Ignore 模版",
"type": "string"
},
"license_template": {
"description": "License 模版",
"type": "string"
},
"path": {
"description": "仓库路径",
"type": "string"
},
"private": {
"description": "是否私有",
"type": "boolean"
},
"default_branch": {
"description": "初始化项目时的默认分支名称。默认:main",
"type": "string",
"default": "main"
},
"import_url": {
"description": "导入项目的 git 地址;与 project_template 互斥,只能传入一个",
"type": "string"
},
"project_template": {
"description": "模板项目的 path;与 import_url 互斥,只能传入一个",
"type": "string"
},
"repository_type": {
"description": "仓库类型:code(代码仓)、model(模型仓)、dataset(数据集仓)、space(Space 仓)。默认 code",
"type": "string",
"enum": ["code", "model", "dataset", "space"],
"default": "code"
}
},
"required": ["name"]
}
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
id |
integer | 是 | 否 | 仓库 ID |
full_name |
string | 是 | 否 | 仓库完整名称(所有者/仓库名) |
human_name |
string | 是 | 否 | 仓库可读名称(所有者 / 仓库名) |
url |
string | 是 | 否 | 仓库 API 地址 |
namespace |
object | 是 | 否 | 所属命名空间信息 |
path |
string | 是 | 否 | 仓库路径 |
name |
string | 是 | 否 | 仓库名称 |
description |
string | 是 | 是 | 仓库描述,可为空 |
private |
boolean | 是 | 否 | 是否私有 |
public |
boolean | 是 | 否 | 是否公开 |
visibility |
string | 是 | 否 | 可见性(如 private / public) |
namespace 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
namespace.id |
integer | 是 | 否 | 命名空间 ID |
namespace.name |
string | 是 | 否 | 命名空间名称 |
namespace.path |
string | 是 | 否 | 命名空间路径 |
namespace.develop_mode |
string | 是 | 否 | 开发模式(如 normal) |
namespace.kind |
string | 是 | 否 | 命名空间类型(如 user) |
namespace.full_path |
string | 是 | 否 | 命名空间完整路径 |
namespace.full_name |
string | 是 | 否 | 命名空间完整名称 |
namespace.visibility_level |
integer | 是 | 否 | 可见性级别 |
namespace.enable_file_control |
boolean | 是 | 否 | 是否启用文件权限控制 |
namespace.owner_id |
integer | 是 | 否 | 所有者 ID |
失败响应¶
以下为常见的失败响应示例,错误字段名以后端实际返回为准。
400 参数错误
401 未认证
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误或请求无法解析 |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
请求路径不存在 |
500 |
系统内部错误 |
请求示例¶
参数说明¶
示例中的 <token> 替换为你的 AtomGit 用户访问令牌;name 为必填的仓库名称,其余请求体字段均为可选。请求参数与请求体字段请与上文保持一致,照抄即可调用成功。
cURL¶
curl -X POST 'https://api.atomgit.com/api/v5/user/repos?access_token=<token>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"name": "my-project",
"path": "my-project",
"description": "我的第一个仓库",
"private": false,
"auto_init": true,
"default_branch": "main",
"has_issues": true,
"has_wiki": true,
"can_comment": true,
"repository_type": "code"
}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/user/repos?access_token=<token>", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
name: "my-project",
path: "my-project",
description: "我的第一个仓库",
private: false,
auto_init: true,
default_branch: "main",
repository_type: "code",
}),
});
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.post(
"https://api.atomgit.com/api/v5/user/repos",
params={"access_token": "<token>"},
headers={"Content-Type": "application/json", "Accept": "application/json"},
json={
"name": "my-project",
"path": "my-project",
"description": "我的第一个仓库",
"private": False,
"auto_init": True,
"default_branch": "main",
"repository_type": "code",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"id": 4106383,
"full_name": "dengmengmian/wunian-prj",
"human_name": "dengmengmian / wunian-prj",
"url": "https://api.atomgit.com/api/v5/user/repos",
"namespace": {
"id": 199940,
"name": "dengmengmian",
"path": "dengmengmian",
"develop_mode": "normal",
"kind": "user",
"full_path": "dengmengmian",
"full_name": "dengmengmian",
"visibility_level": 20,
"enable_file_control": false,
"owner_id": 268
},
"path": "wunian-prj",
"name": "wunian-prj",
"description": "wunian-prj",
"private": true,
"public": false,
"visibility": "private"
}
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
403 |
禁止访问 |
404 |
请求路径不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc