创建仓库¶
POST /api/v5/orgs/{org}/repos
该接口用于在指定组织下创建新仓库,支持代码、模型、数据集等多种仓库类型,可设置公开或私有可见性,并支持配置默认分支、初始化说明以及导入外部项目等功能。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
org |
path | string | 是 | 组织的路径(path/login) |
access_token |
query | string | 是 | 用户授权码 |
Request Body:
请求体为 application/json 格式,字段定义如下:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": {
"description": "仓库名称",
"type": "string"
},
"description": {
"description": "仓库描述",
"type": "string"
},
"homepage": {
"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
},
"public": {
"description": "仓库开源类型,0(私有),1(公开)",
"type": "integer",
"enum": [0, 1]
},
"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"
},
"default_branch": {
"description": "初始化项目时的默认分支名称,默认 main",
"type": "string",
"default": "main"
},
"import_url": {
"description": "导入项目的 git 地址,import_url 和 project_template 参数只能传入一个",
"type": "string"
},
"project_template": {
"description": "模板项目的 path,import_url 和 project_template 参数只能传入一个",
"type": "string"
},
"repository_type": {
"description": "仓库类型,code:代码仓,model:模型仓,dataset:数据集仓,space:space,默认 code",
"type": "string",
"enum": ["code", "model", "dataset", "space"],
"default": "code"
}
},
"required": ["name"]
}
Note: 请求参数 public 为整数(0 私有 / 1 公开);响应中的 private / public 字段在示例中以布尔值返回,两者含义一致,仅表示形式不同。
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
id |
integer | 是 | 否 | 仓库 ID |
full_name |
string | 是 | 否 | 仓库完整名称(空间路径/仓库路径) |
human_name |
string | 是 | 否 | 仓库的人类可读名称 |
url |
string | 是 | 否 | 仓库的 API 地址 |
path |
string | 是 | 否 | 仓库路径 |
name |
string | 是 | 否 | 仓库名称 |
description |
string | 是 | 是 | 仓库描述,可能为 null |
private |
integer | 是 | 是 | 是否私有仓库(0/1,示例中可能返回布尔值),可能为 null |
public |
integer | 是 | 是 | 是否公开仓库(0/1,示例中可能返回布尔值),可能为 null |
namespace |
object | 是 | 是 | 仓库所属空间(组织/用户)信息 |
visibility |
string | 是 | 是 | 仓库可见性,可能为 null |
homepage |
string | 是 | 是 | 仓库主页,可能为 null |
namespace 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
namespace.id |
integer | 是 | 否 | 空间 ID |
namespace.name |
string | 是 | 否 | 空间名称 |
namespace.path |
string | 是 | 否 | 空间路径 |
namespace.develop_mode |
string | 是 | 是 | 开发模式,可能为 null |
namespace.cell |
string | 是 | 是 | 空间单元,可能为 null |
namespace.kind |
string | 是 | 是 | 空间类型(如 group),可能为 null |
namespace.full_path |
string | 是 | 否 | 空间完整路径 |
namespace.full_name |
string | 是 | 否 | 空间完整名称 |
namespace.visibility_level |
integer | 是 | 否 | 可见性级别 |
namespace.enable_file_control |
integer | 是 | 是 | 是否启用文件控制(示例中可能返回布尔值),可能为 null |
namespace.region |
string | 否 | 是 | 区域,以实际返回为准 |
namespace.parent_id |
integer | 否 | 是 | 父空间 ID,以实际返回为准 |
namespace.owner_id |
integer | 否 | 是 | 空间所有者 ID,以实际返回为准 |
Note: 实际响应中还可能包含 empty_repo、starred、owner、creator、forked_from_project、item_type、main_repository_language 等可空字段(示例中均为 null),以实际返回为准。
失败响应¶
400 参数错误
401 未认证
Note: 错误响应字段名(error / message / field)以后端实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误(Bad request) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
未找到(Not found) |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
请求示例¶
参数说明¶
示例中的占位符说明:
<org>替换为组织的路径(path/login);<token>替换为你的 AtomGit 用户访问令牌。
cURL¶
curl -X POST 'https://api.atomgit.com/api/v5/orgs/<org>/repos?access_token=<token>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"name": "my-repo",
"description": "仓库描述",
"has_issues": true,
"has_wiki": true,
"can_comment": true,
"public": 1,
"auto_init": true,
"gitignore_template": "Java",
"license_template": "MIT",
"path": "my-repo",
"default_branch": "main",
"repository_type": "code"
}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/orgs/<org>/repos?access_token=<token>", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
name: "my-repo",
description: "仓库描述",
has_issues: true,
has_wiki: true,
can_comment: true,
public: 1,
auto_init: true,
gitignore_template: "Java",
license_template: "MIT",
path: "my-repo",
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/orgs/<org>/repos",
params={"access_token": "<token>"},
json={
"name": "my-repo",
"description": "仓库描述",
"has_issues": True,
"has_wiki": True,
"can_comment": True,
"public": 1,
"auto_init": True,
"gitignore_template": "Java",
"license_template": "MIT",
"path": "my-repo",
"default_branch": "main",
"repository_type": "code",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"id": 34171993,
"full_name": "daming_1/test_create_project_2",
"human_name": "daming/test_create_project_2",
"url": "https://api.atomgit.com/api/v5/repos/daming_1/test_create_project_2",
"path": "test_create_project_2",
"name": "test_create_project_2",
"description": "描述",
"private": false,
"public": true,
"namespace": {
"id": 74962,
"name": "group1111",
"path": "group11111",
"develop_mode": "normal",
"region": null,
"cell": "default",
"kind": "group",
"full_path": "group11111",
"full_name": "group1111",
"parent_id": null,
"visibility_level": 20,
"enable_file_control": false,
"owner_id": null
},
"empty_repo": null,
"starred": null,
"visibility": "public",
"owner": null,
"creator": null,
"forked_from_project": null,
"item_type": null,
"main_repository_language": null,
"homepage": "http://www.baidi.com"
}
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
403 |
禁止访问 |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc