Pull Request Commit文件列表¶
GET /api/v5/repos/{owner}/{repo}/pulls/{number}/files
该接口用于查询指定仓库中某个 Pull Request(合并请求)变更所涉及的文件列表,返回每个变更文件的路径、状态、新增与删除行数、diff 补丁信息,以及源、目标分支和所属仓库等数据。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(企业、组织或个人的地址 path) |
repo |
path | string | 是 | 仓库路径(path) |
number |
path | integer | 是 | 第几个 PR,即本仓库 PR 的序数(对应 iid) |
响应参数¶
接口返回一个数组,数组元素为 Pull Request 中每个变更文件的变更信息。
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
sha |
string | 是 | 否 | 文件变更对应的提交 SHA |
filename |
string | 是 | 否 | 文件路径 |
status |
string | 是 | 是 | 变更状态,可能为 null |
additions |
integer | 是 | 是 | 新增行数 |
deletions |
integer | 是 | 是 | 删除行数 |
blob_url |
string | 是 | 是 | 变更文件的 blob 页面地址 |
raw_url |
string | 是 | 是 | 变更文件的 raw 内容地址 |
patch |
object | 是 | 是 | 变更补丁信息(diff 等) |
target_branch |
string | 是 | 是 | 目标分支 |
source_branch |
string | 是 | 是 | 源分支 |
target_project |
object | 是 | 是 | 目标仓库信息 |
source_project |
object | 是 | 是 | 源仓库信息 |
patch 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
patch.diff |
string | 是 | 是 | 变更的 diff 内容 |
patch.old_path |
string | 是 | 是 | 变更前的文件路径 |
patch.new_path |
string | 是 | 是 | 变更后的文件路径 |
patch.a_mode |
string | 是 | 是 | 变更前的文件模式(如 100644) |
patch.b_mode |
string | 是 | 是 | 变更后的文件模式(如 100644) |
patch.new_file |
boolean | 是 | 是 | 是否为新增文件 |
patch.renamed_file |
boolean | 是 | 是 | 是否为重命名文件 |
patch.deleted_file |
boolean | 是 | 是 | 是否为删除文件 |
patch.too_large |
boolean | 是 | 是 | 文件是否过大 |
patch.added_lines |
integer | 是 | 是 | 补丁中新增行数 |
patch.removed_lines |
integer | 是 | 是 | 补丁中删除行数 |
target_project 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
target_project.id |
string | 是 | 否 | 仓库 ID |
target_project.full_name |
string | 是 | 否 | 仓库完整名称 |
target_project.human_name |
string | 是 | 否 | 人类可读名称 |
target_project.path |
string | 是 | 否 | 仓库路径 |
source_project 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
source_project.id |
string | 是 | 否 | 仓库 ID |
source_project.full_name |
string | 是 | 否 | 仓库完整名称 |
source_project.human_name |
string | 是 | 否 | 人类可读名称 |
source_project.path |
string | 是 | 否 | 仓库路径 |
失败响应¶
参考文档未提供该接口的业务失败响应示例。当仓库或 Pull Request 不存在、参数无效或权限不足时,接口将返回非 2xx 状态码,错误体结构以实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误 |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
仓库或 Pull Request 不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(企业、组织或个人的地址 path);<repo>替换为仓库路径(path);<number>替换为第几个 PR,即本仓库 PR 的序数。
本接口允许匿名访问,示例未携带访问令牌;如需要,也可在 URL 上追加 ?access_token=<token>(将 <token> 替换为你的 AtomGit 用户访问令牌)。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/files' \
-H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/files", {
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>/files",
headers={
"Accept": "application/json",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
[
{
"sha": "45e1211262a0ed24eeb85ac37f7776259ef0e7e1",
"filename": "README.md",
"status": null,
"additions": 3,
"deletions": 1,
"blob_url": "https://api.atomgit.com/<owner>/<repo>/blob/45e1211262a0ed24eeb85ac37f7776259ef0e7e1/README.md",
"raw_url": "https://api.atomgit.com/<owner>/<repo>/raw/45e1211262a0ed24eeb85ac37f7776259ef0e7e1/README.md",
"patch": {
"diff": "@@ -1,3 +1,4 @@\n+# new line added\n demo content",
"new_path": "README.md",
"old_path": "README.md",
"a_mode": "100644",
"b_mode": "100644",
"new_file": false,
"renamed_file": false,
"deleted_file": false,
"too_large": false,
"added_lines": 3,
"removed_lines": 1
},
"target_branch": "master",
"source_branch": "feature/demo",
"target_project": {
"id": "1",
"full_name": "<owner>/<repo>",
"human_name": "<owner>/<repo>",
"path": "<repo>"
},
"source_project": {
"id": "1",
"full_name": "<owner>/<repo>",
"human_name": "<owner>/<repo>",
"path": "<repo>"
}
}
]
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效 |
403 |
禁止访问(Forbidden) |
404 |
仓库或 Pull Request 不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc