仓库的某个提交¶
GET /api/v5/repos/{owner}/{repo}/commits/{sha}
该接口用于查询指定仓库中某个提交的详细信息,包括提交信息、作者与提交者、变更统计及变更文件列表,可通过 show_diff 参数控制是否返回文件变更明细。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(企业、组织或个人的地址 path) |
repo |
path | string | 是 | 仓库路径(path) |
sha |
path | string | 是 | 提交的 SHA 值或者分支名 |
show_diff |
query | boolean | 否 | 默认为 false;为 true 时返回 files 字段,files 字段中包含该提交中的至多 100 个变更文件名 |
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
url |
string | 是 | 否 | 该提交的 API 地址 |
sha |
string | 是 | 否 | 该提交的 SHA 值 |
html_url |
string | 是 | 否 | 该提交的网页地址 |
comments_url |
string | 是 | 否 | 该提交评论的 API 地址 |
commit |
object | 是 | 否 | 提交信息 |
stats |
object | 是 | 否 | 提交统计信息 |
files |
object[] | 否 | 是 | 变更文件列表,show_diff=true 时返回,至多 100 个 |
parents |
object[] | 是 | 否 | 父提交列表 |
co_authors |
object[] | 是 | 是 | 共同作者列表 |
commit 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.author |
object | 是 | 否 | 提交作者信息 |
commit.committer |
object | 是 | 否 | 提交者信息 |
commit.message |
string | 是 | 否 | 提交信息 |
commit.author 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.author.name |
string | 是 | 否 | 作者姓名 |
commit.author.date |
string | 是 | 否 | 提交日期(ISO 8601 格式) |
commit.author.email |
string | 是 | 否 | 作者邮箱 |
commit.committer 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.committer.name |
string | 是 | 否 | 提交者姓名 |
commit.committer.date |
string | 是 | 否 | 提交日期(ISO 8601 格式) |
commit.committer.email |
string | 是 | 否 | 提交者邮箱 |
stats 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
stats.additions |
integer | 是 | 否 | 新增行数 |
stats.deletions |
integer | 是 | 否 | 删除行数 |
stats.total |
integer | 是 | 否 | 变更总行数 |
files 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
files[].sha |
string | 否 | 是 | 文件在提交中的 SHA 值 |
files[].filename |
string | 否 | 是 | 变更文件名 |
files[].status |
string | 否 | 是 | 文件状态 |
files[].additions |
integer | 否 | 是 | 新增行数 |
files[].deletions |
integer | 否 | 是 | 删除行数 |
files[].changes |
integer | 否 | 是 | 变更行数 |
files[].raw_url |
string | 否 | 是 | 原始文件地址 |
files[].content_url |
string | 否 | 是 | 文件内容地址 |
parents 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
parents[].sha |
string | 是 | 否 | 父提交的 SHA 值 |
parents[].url |
string | 是 | 否 | 父提交的 API 地址 |
co_authors 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
co_authors[].id |
string | 是 | 否 | 共同作者 ID |
co_authors[].login |
string | 是 | 否 | 共同作者登录名 |
co_authors[].name |
string | 是 | 否 | 共同作者姓名 |
co_authors[].avatar_url |
string | 是 | 否 | 共同作者头像地址 |
co_authors[].html_url |
string | 是 | 否 | 共同作者主页地址 |
co_authors[].email |
string | 是 | 否 | 共同作者邮箱 |
失败响应¶
该接口在参数校验失败、提交不存在或认证失败时返回错误响应。错误字段名以后端实际返回为准。
400 参数错误
401 未认证
404 提交不存在
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
304 |
未修改(Not modified) |
401 |
需要认证(Requires authentication) |
404 |
仓库或提交不存在(Not found) |
请求示例¶
参数说明¶
该接口允许匿名访问,请求时可不携带访问令牌;如需访问私有仓库资源,也可携带 AtomGit 用户访问令牌。
<owner>替换为仓库所属空间地址 path(企业、组织或个人的地址 path);<repo>替换为仓库路径(path);<sha>替换为提交的 SHA 值或分支名。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<sha>?show_diff=true' -H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<sha>?show_diff=true", {
headers: {
"Accept": "application/json",
},
});
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.get(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<sha>?show_diff=true",
headers={"Accept": "application/json"},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"url": "https://api.atomgit.com/api/v5/repos/daming_1/zhu_di/commits/7ffc0a0deb709143f6be12a55e218fab9233ca37",
"sha": "7ffc0a0deb709143f6be12a55e218fab9233ca37",
"html_url": "https://api.atomgit.com/daming_1/zhu_di/commit/7ffc0a0deb709143f6be12a55e218fab9233ca37",
"comments_url": "https://api.atomgit.com/api/v5/repos/daming_1/zhu_di/commits/7ffc0a0deb709143f6be12a55e218fab9233ca37/comments",
"commit": {
"author": {
"name": "占分",
"date": "2024-04-14T07:25:11+00:00",
"email": "7543745+centking@user.noreply.atomgit.com"
},
"committer": {
"name": "AtomGit",
"date": "2024-04-14T07:25:11+00:00",
"email": "noreply@atomgit.com"
},
"message": "提交信息测试"
},
"stats": {
"additions": 1,
"deletions": 1,
"total": 2
},
"files": [
{
"sha": "b0e267d8bbed9b568623528c216f8f8489689a61",
"filename": "pom.xml",
"status": "modified",
"additions": 1,
"deletions": 1,
"changes": 2,
"raw_url": "https://raw.atomgit.com/test-owner/test-repo/raw/b0e267d8bbed9b568623528c216f8f8489689a61/pom.xml",
"content_url": "https://api.atomgit.com/test-owner/test-repo/blob/b0e267d8bbed9b568623528c216f8f8489689a61/pom.xml"
}
],
"parents": [
{
"sha": "6c7a2c0a5c5b2a3c4d5e6f7a8b9c0d1e2f3a4b5c",
"url": "https://api.atomgit.com/api/v5/repos/daming_1/zhu_di/commits/6c7a2c0a5c5b2a3c4d5e6f7a8b9c0d1e2f3a4b5c"
}
],
"co_authors": [
{
"id": "12345",
"login": "octocat",
"name": "Octo Cat",
"avatar_url": "https://api.atomgit.com/avatar/octocat.png",
"html_url": "https://api.atomgit.com/octocat",
"email": "octocat@atomgit.com"
}
]
}
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效 |
404 |
仓库或提交不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc