获取某个Pull Request的所有评论¶
GET /api/v5/repos/{owner}/{repo}/pulls/{number}/comments
获取指定仓库中某个 Pull Request 的全部评论,支持按评论类型筛选与分页排序。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(企业、组织或个人的地址path) |
repo |
path | string | 是 | 仓库路径(path) |
number |
path | integer | 是 | 第几个PR,即本仓库PR的序数 |
direction |
query | string | 否 | 可选。升序/降序;枚举:asc / desc |
comment_type |
query | string | 否 | 可选。筛选评论类型;枚举:diff_comment(代码行评论) / pr_comment(PR 普通评论) |
view |
query | string | 否 | 查询视图类型。为空时服务端按 basic 处理;传 all 时表示不限视图(内部转换为空视图) |
page |
query | integer | 否 | 当前页码。需为整数 |
per_page |
query | integer | 否 | 每页的条目数。需为整数 |
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
id |
integer | 是 | 否 | 评论 ID |
discussion_id |
string | 是 | 是 | 评论所属讨论 ID |
body |
string | 是 | 是 | 评论内容 |
created_at |
string | 是 | 是 | 评论创建时间 |
updated_at |
string | 是 | 是 | 评论更新时间 |
user |
object | 是 | 是 | 评论作者 |
commentType |
string | 是 | 是 | 评论类型,pr_comment 表示普通评论,diff_comment 表示代码差异评论 |
resolved |
boolean | 是 | 是 | 检视意见是否已解决 |
resolved_by |
object | 是 | 是 | 检视意见解决人,仅在检视意见已解决时返回 |
diffFile |
string | 是 | 是 | 评论关联的差异文件信息 |
diffPosition |
object | 是 | 是 | 代码差异评论关联的行位置,仅代码行评论返回 |
reply |
array | 是 | 是 | 当前讨论下的回复列表 |
isOutdated |
boolean | 是 | 是 | 检视意见是否已过时 |
user 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
user.id |
string | 是 | 是 | 用户 ID |
user.login |
string | 是 | 是 | 用户名 |
user.objectId |
string | 是 | 是 | 用户对象 ID |
user.name |
string | 是 | 是 | 用户昵称 |
user.avatar_url |
string | 是 | 是 | 用户头像地址 |
user.html_url |
string | 是 | 是 | 用户个人主页地址 |
resolved_by 对象
字段结构同 user 对象。
diffPosition 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
diffPosition.startNewLine |
integer | 是 | 是 | 新版本文件的起始行号 |
diffPosition.endNewLine |
integer | 是 | 是 | 新版本文件的结束行号 |
diffPosition.startOldLine |
integer | 是 | 是 | 旧版本文件的起始行号 |
diffPosition.endOldLine |
integer | 是 | 是 | 旧版本文件的结束行号 |
diffPosition.positionType |
string | 是 | 是 | 差异位置类型 |
reply 数组元素
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
reply.id |
integer | 是 | 否 | 回复 ID |
reply.body |
string | 是 | 是 | 回复内容 |
reply.created_at |
string | 是 | 是 | 回复创建时间 |
reply.updated_at |
string | 是 | 是 | 回复更新时间 |
reply.user |
object | 是 | 是 | 回复作者,字段结构同 user 对象 |
失败响应¶
该接口的失败响应由通用鉴权与网关层产生,响应体字段以后端实际返回为准。
401 未认证
404 资源不存在
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
304 |
未修改(Not modified) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
资源不存在(Not found) |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(企业、组织或个人的地址 path) 如果是三段命名空间,例如: gh_mirrors/co/QwenPaw。owner值为gh_mirrors/co,调用时必须把第一个/编码为%2F,owner传值为: gh_mirrors%2Fco。
<repo>替换为仓库路径名
<number>替换为本仓库 PR 的序数
<token>替换为你的 AtomGit 用户访问令牌(匿名访问时可省略)。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/comments?direction=desc&comment_type=pr_comment&page=1&per_page=20' \
-H 'Authorization: Bearer <token>' \
-H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/comments?page=1&per_page=20", {
headers: {
"Accept": "application/json",
"Authorization": "Bearer <YOUR-TOKEN>",
},
});
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>/comments",
params={"page": 1, "per_page": 20},
headers={
"Accept": "application/json",
"Authorization": "Bearer <YOUR-TOKEN>",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
[
{
"id": 1001,
"discussion_id": "a1b2c3d4e5",
"body": "这里的空指针需要处理",
"created_at": "2024-04-20 14:39:00",
"updated_at": "2024-04-20 15:02:00",
"user": {
"id": "10001",
"login": "octocat",
"objectId": "obj-10001",
"name": "Octo Cat",
"avatar_url": "https://api.atomgit.com/avatar.png",
"html_url": "https://api.atomgit.com/octocat"
},
"commentType": "diff_comment",
"resolved": false,
"resolved_by": null,
"diffFile": "src/main/java/com/example/Demo.java",
"diffPosition": {
"startNewLine": 42,
"endNewLine": 43,
"startOldLine": 42,
"endOldLine": 42,
"positionType": "text"
},
"reply": [
{
"id": 1002,
"body": "已修复,请复核",
"created_at": "2024-04-20 16:10:00",
"updated_at": "2024-04-20 16:10:00",
"user": {
"id": "10002",
"login": "developer",
"objectId": "obj-10002",
"name": "Developer",
"avatar_url": "https://api.atomgit.com/avatar2.png",
"html_url": "https://api.atomgit.com/developer"
}
}
],
"isOutdated": false
}
]
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
403 |
无权访问该仓库或该 Pull Request |
404 |
请求路径、仓库或 Pull Request 不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc