获取某Pull Request的所有Commit信息¶
GET /api/v5/repos/{owner}/{repo}/pulls/{number}/commits
该接口用于获取指定仓库中某个 Pull Request 的全部 Commit 信息,返回内容包括提交的 SHA、提交说明、作者与提交者信息、父提交信息以及共同作者列表,并支持分页查询。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(组织或个人的地址 path) |
repo |
path | string | 是 | 仓库路径(path) |
number |
path | integer | 是 | 第几个 PR,即本仓库 PR 的序数,示例 0 |
page |
query | string | 否 | 当前页码 |
per_page |
query | string | 否 | 每页数量 |
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
sha |
string | 是 | — | 提交的 SHA |
html_url |
string | 是 | — | 提交对应的 HTML 地址 |
commit |
object | 是 | — | 提交信息 |
author |
object | 是 | — | 提交作者信息 |
committer |
object | 是 | — | 提交者信息 |
parents |
object | 是 | — | 父提交信息 |
co_authors |
object[] | 是 | — | 共同作者列表 |
commit 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.author |
object | 是 | — | 提交作者信息 |
commit.committer |
object | 是 | — | 提交者信息 |
commit.message |
string | 是 | — | 提交说明 |
commit.author 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.author.login |
string | 否 | — | 登录名 |
commit.author.name |
string | 是 | — | 姓名 |
commit.author.email |
string | 是 | — | 邮箱 |
commit.author.date |
string | 是 | — | 提交日期 |
commit.committer 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.committer.login |
string | 否 | — | 登录名 |
commit.committer.name |
string | 是 | — | 姓名 |
commit.committer.email |
string | 是 | — | 邮箱 |
author 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
author.id |
string | 是 | — | 用户 ID |
author.login |
string | 是 | — | 登录名 |
author.name |
string | 是 | — | 姓名 |
author.avatar_url |
string | 是 | — | 头像地址 |
author.html_url |
string | 是 | — | 主页地址 |
author.object_id |
string | 是 | — | 对象 ID |
committer 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
committer.id |
string | 是 | — | 用户 ID |
committer.login |
string | 是 | — | 登录名 |
committer.name |
string | 是 | — | 姓名 |
committer.avatar_url |
string | 是 | — | 头像地址 |
committer.html_url |
string | 是 | — | 主页地址 |
committer.object_id |
string | 是 | — | 对象 ID |
parents 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
parents.sha |
string | 是 | — | 父提交的 SHA |
parents.shas |
string[] | 是 | — | 父提交 SHA 列表 |
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) |
403 |
禁止访问(Forbidden) |
404 |
未找到(Not found) |
请求示例¶
参数说明¶
本接口允许匿名访问,调用时无需携带访问令牌;如需以更高权限访问,也可在查询参数中追加 access_token=<token>。
<owner>替换为仓库所属空间地址(组织或个人的地址 path);<repo>替换为仓库路径(path);<number>替换为第几个 PR(即本仓库 PR 的序数);<token>替换为你的 AtomGit 用户访问令牌。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/commits?page=1&per_page=30' \
-H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/commits?page=1&per_page=30",
{
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>/pulls/<number>/commits",
params={"page": 1, "per_page": 30},
headers={"Accept": "application/json"},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
[
{
"sha": "91861a9668041fc1c0ff51d1db66b6297179f5e6",
"html_url": "https://api.atomgit.com/sytest/paopao/blob/91861a9668041fc1c0ff51d1db66b6297179f5e6",
"commit": {
"author": {
"login": "test",
"name": "test",
"email": "test@test.com",
"date": "2024-03-28T11:19:33+08:00"
},
"committer": {
"login": "test",
"name": "test",
"email": "test@test.com"
},
"message": "!5 333 * add 1/2/3/4. * add 1/2/3. "
},
"author": {
"id": "id123",
"login": "test",
"name": "test",
"avatar_url": "https://api.atomgit.com/pic.png",
"html_url": "https://api.atomgit.com/test"
},
"committer": {
"id": "id123",
"login": "test",
"name": "test",
"avatar_url": "https://api.atomgit.com/pic.png",
"html_url": "https://api.atomgit.com/test"
},
"parents": {
"sha": "2e208a1e38f6a5a7b0cc3787688067ba082a8bb7",
"shas": [
"2e208a1e38f6a5a7b0cc3787688067ba082a8bb7"
]
},
"co_authors": [
{
"id": "id123",
"login": "test",
"name": "test",
"avatar_url": "https://api.atomgit.com/pic.png",
"html_url": "https://api.atomgit.com/test",
"email": "test@test.com"
}
]
}
]
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
400 |
参数错误或请求无法解析 |
404 |
请求路径不存在或资源未找到 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc