pr提交的文件变更信息¶
GET /api/v5/repos/{owner}/{repo}/pulls/{number}/files.json
该接口用于查询指定 PR 提交的文件变更信息,返回文件变更数量、新增与删除行数、对比引用的 commit 信息,以及各文件的具体差异内容,包含文件路径、行级增删记录等。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(组织或个人的地址 path) |
repo |
path | string | 是 | 仓库路径(path) |
number |
path | integer | 是 | 第几个 PR,即本仓库 PR 的序数 |
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
code |
integer | — | — | 响应状态码,0 表示成功 |
added_lines |
integer | — | — | 新增行数 |
remove_lines |
integer | — | — | 删除行数 |
count |
integer | — | — | 文件变更数量 |
diff_refs |
object | — | — | 对比引用的 commit 信息 |
diffs |
array | — | — | 文件变更列表 |
diff_refs 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diff_refs.base_sha |
string | — | — | 对比基准 commit 的 sha |
diff_refs.start_sha |
string | — | — | 起始 commit 的 sha |
diff_refs.head_sha |
string | — | — | 最新 commit 的 sha |
diffs 数组元素对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diffs.new_blob_id |
string | — | — | 新文件 blob 的 id |
diffs.statistic |
object | — | — | 文件统计信息 |
diffs.head |
object | — | — | 文件对应的 commit 信息 |
diffs.added_lines |
integer | — | — | 该文件新增行数 |
diffs.remove_lines |
integer | — | — | 该文件删除行数 |
diffs.content |
object | — | — | 文件内容差异 |
diffs.statistic 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diffs.statistic.type |
string | — | — | 文件类型(示例值 text_type) |
diffs.statistic.path |
string | — | — | 文件路径 |
diffs.statistic.old_path |
string | — | — | 原文件路径 |
diffs.statistic.new_path |
string | — | — | 新文件路径 |
diffs.statistic.view |
integer | — | — | 视图标识 |
diffs.head 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diffs.head.url |
string | — | — | 文件内容地址 |
diffs.head.commit_id |
string | — | — | commit id |
diffs.content 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diffs.content.text |
array | — | — | 差异行文本列表 |
diffs.content.text 数组元素对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diffs.content.text.line_content |
string | — | — | 行内容 |
diffs.content.text.old_line |
object | — | — | 旧行信息 |
diffs.content.text.new_line |
object | — | — | 新行信息 |
diffs.content.text.type |
string | — | — | 行类型(old / new) |
diffs.content.text.old_line 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diffs.content.text.old_line.line_code |
string | — | — | 旧行行号编码 |
diffs.content.text.old_line.line_num |
string | — | — | 旧行行号,无对应行时为 "" |
diffs.content.text.new_line 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diffs.content.text.new_line.line_code |
string | — | — | 新行行号编码 |
diffs.content.text.new_line.line_num |
string | — | — | 新行行号,无对应行时为 "" |
失败响应¶
只有
200/成功响应是不够的:调用方需要知道失败长什么样才能写错误处理。
400 参数错误
401 未认证
404 资源不存在
错误字段名以后端实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
304 |
未修改(Not modified) |
400 |
参数错误(Bad request) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
未找到(Not found) |
405 |
请求方法不支持(Method not allowed) |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误(Internal server error) |
请求示例¶
参数说明¶
示例必须与本文档其余部分自洽,照抄即可调用成功。本接口允许匿名访问,请求示例中未携带令牌;若需要认证,也可在 URL 中追加 ?access_token=<token> 携带 AtomGit 用户访问令牌。
<owner>替换为仓库所属空间地址(组织或个人的地址 path);<repo>替换为仓库路径(path);<number>替换为第几个 PR,即本仓库 PR 的序数。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/files.json' \
-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.json", {
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.json",
headers={"Accept": "application/json"},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"code": 0,
"added_lines": 7,
"remove_lines": 7,
"count": 2,
"diff_refs": {
"base_sha": "db015522f67b15e868c5f929ff1af4cba9ddd112",
"start_sha": "db015522f67b15e868c5f929ff1af4cba9ddd112",
"head_sha": "93cd8303ac07886610d738baf7ddd620f04ee778"
},
"diffs": [
{
"new_blob_id": "b575bd06b44029dc12771503388d61ea383169cb",
"statistic": {
"type": "text_type",
"path": "1",
"old_path": "1",
"new_path": "1",
"view": 0
},
"head": {
"url": "https://api.atomgit.com/xiaogang/test/raw/93cd8303ac07886610d738baf7ddd620f04ee778/1",
"commit_id": "93cd8303ac07886610d738baf7ddd620f04ee778"
},
"added_lines": 3,
"remove_lines": 3,
"content": {
"text": [
{
"line_content": "111",
"old_line": {
"line_code": "356a192b7913b04c54574d18c28d46e6395428ab_1_1",
"line_num": "1"
},
"new_line": {
"line_code": "356a192b7913b04c54574d18c28d46e6395428ab_1_1",
"line_num": ""
},
"type": "old"
},
{
"line_content": "111222",
"old_line": {
"line_code": "356a192b7913b04c54574d18c28d46e6395428ab_2_1",
"line_num": ""
},
"new_line": {
"line_code": "356a192b7913b04c54574d18c28d46e6395428ab_2_1",
"line_num": "1"
},
"type": "new"
}
]
}
}
]
}
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc