删除文件¶
DELETE /api/v5/repos/{owner}/{repo}/contents/{path}
该接口用于删除仓库中指定分支上的文件,通过指定文件路径及其 Blob SHA 确认目标文件,删除操作将自动生成对应的提交记录,并返回本次删除操作的提交信息。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(企业、组织或个人的地址 path) |
repo |
path | string | 是 | 仓库路径(path) |
path |
path | string | 是 | 文件的路径 |
access_token |
query | string | 是 | 用户授权码 |
Request Body:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"sha": {
"description": "文件的 Blob SHA",
"type": "string"
},
"message": {
"description": "提交信息",
"type": "string"
},
"branch": {
"description": "分支名称。默认为仓库的默认分支",
"type": "string"
}
},
"required": ["sha", "message"]
}
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit |
object | 是 | 否 | 提交信息 |
content |
object | 否 | 是 | 文件信息(删除操作通常返回 null) |
commit 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.sha |
string | 是 | 否 | commit ID |
commit.author |
object | 是 | 否 | 作者信息 |
commit.committer |
object | 是 | 否 | 提交者信息 |
commit.message |
string | 是 | 否 | 提交信息 |
commit.tree |
string | 是 | 否 | tree ID |
commit.parents |
string[] | 是 | 是 | 父节点(父提交 ID 列表) |
commit.author 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.author.name |
string | 是 | 否 | 作者名称 |
commit.author.email |
string | 是 | 否 | 作者邮箱 |
commit.author.date |
string | 是 | 否 | 提交时间 |
commit.committer 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.committer.name |
string | 是 | 否 | 提交者名称 |
commit.committer.email |
string | 是 | 否 | 提交者邮箱 |
commit.committer.date |
string | 是 | 否 | 提交时间 |
content 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content.name |
string | 是 | 否 | 名称 |
content.path |
string | 是 | 否 | 路径 |
content.size |
integer | 是 | 是 | 大小 |
content.sha |
string | 是 | 否 | blob ID |
content.type |
string | 是 | 否 | 类型(file) |
失败响应¶
400 参数错误
401 未认证
Note: 错误字段名以后端实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
304 |
未修改(Not modified) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
请求示例¶
参数说明¶
示例采用以下占位符:
<owner>— 仓库所属空间地址(企业、组织或个人的地址 path);<repo>— 仓库路径(path);<path>— 要删除的文件路径(支持多级目录,如docs/readme.md);<token>— 你的 AtomGit 用户访问令牌;<file_blob_sha>— 文件当前版本的 Blob SHA。
cURL¶
curl -X DELETE 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/contents/<path>?access_token=<token>' \
-H 'Content-Type: application/json' \
-d '{
"sha": "<file_blob_sha>",
"message": "删除文件",
"branch": "master"
}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/contents/<path>?access_token=<token>",
{
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
sha: "<file_blob_sha>",
message: "删除文件",
branch: "master",
}),
}
);
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.delete(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/contents/<path>",
params={"access_token": "<token>"},
json={
"sha": "<file_blob_sha>",
"message": "删除文件",
"branch": "master",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"commit": {
"sha": "2a90c33ede2c1eafc5943727fd57129d870ad2e4",
"author": {
"name": "xiaogang",
"email": "1150456356@qq.com",
"date": "2024-11-25T02:11:56.000Z"
},
"committer": {
"name": "xiaogang",
"email": "1150456356@qq.com",
"date": "2024-11-25T02:11:56.000Z"
},
"message": "api删除文件",
"tree": "791f24a0da8c8458e40da3243bde183d59773514",
"parents": [
"33e9ee7ccd32835a0fb9f2af99264931c06fbe11"
]
}
}
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
400 |
参数错误或请求无法解析 |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc