获取Pull Request某条评论¶
GET /api/v5/repos/{owner}/{repo}/pulls/comments/{id}
该接口用于根据评论 ID 获取指定仓库中 Pull Request 的某条评论详情,包括评论内容、作者信息、创建及更新时间,以及评论关联的 Issue 与代码位置信息。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(企业、组织或个人的地址 path) |
repo |
path | string | 是 | 仓库路径(path) |
id |
path | string | 是 | 评论 ID |
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
id |
integer | 是 | 否 | 评论 ID |
discussion_id |
string | 否 | 是 | 讨论 ID |
body |
string | 是 | 是 | 评论内容 |
comment_type |
string | 是 | 是 | 评论类型,例如 DiscussionNote |
user |
object | 是 | 是 | 评论作者的用户信息 |
target |
object | 否 | 是 | 评论目标信息 |
created_at |
string | 是 | 是 | 评论创建时间 |
updated_at |
string | 是 | 是 | 评论更新时间 |
position |
object | 否 | 是 | 评论位置信息 |
user 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
user.id |
string | 是 | 是 | 用户 ID |
user.login |
string | 是 | 是 | 用户登录名 |
user.name |
string | 是 | 是 | 用户昵称 |
user.type |
string | 是 | 是 | 用户类型,例如 User |
target 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
target.issue |
object | 是 | 是 | 关联的 Issue 信息 |
target.issue 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
target.issue.id |
integer | 是 | 是 | Issue ID |
target.issue.title |
string | 是 | 是 | Issue 标题 |
target.issue.number |
string | 是 | 是 | Issue 编号 |
position 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
position.base_sha |
string | 是 | 是 | 基础 SHA |
position.start_sha |
string | 是 | 是 | 起始 SHA |
position.head_sha |
string | 是 | 是 | 头部 SHA |
position.old_path |
string | 是 | 是 | 旧路径 |
position.new_path |
string | 是 | 是 | 新路径 |
position.position_type |
string | 是 | 是 | 位置类型:binary 为文件级评论,text 为代码行评论 |
position.old_line |
integer | 是 | 是 | 旧行号 |
position.new_line |
integer | 是 | 是 | 新行号 |
position.start_old_line |
integer | 是 | 是 | 起始旧行号 |
position.start_new_line |
integer | 是 | 是 | 起始新行号 |
失败响应¶
只有
200成功响应是不够的:调用方需要知道失败长什么样才能写错误处理。
400 参数错误
401 未认证
404 评论不存在
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误(Bad request) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
资源不存在(Not found) |
500 |
系统内部错误(Internal server error) |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(企业、组织或个人的地址 path);<repo>替换为仓库路径(path);<id>替换为评论 ID。
该接口允许匿名访问;若需认证,可携带 AtomGit 用户访问令牌。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/comments/<id>' \
-H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/comments/<id>",
{
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/comments/<id>",
headers={"Accept": "application/json"},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"id": 1486664,
"body": "1111112222222",
"comment_type": "DiscussionNote",
"user": {
"id": "303745",
"login": "yinlin",
"name": "yinlin-昵称",
"type": "User"
},
"target": {
"issue": {
"id": 478892,
"title": "1111",
"number": "478892"
}
},
"created_at": "2024-09-27T14:58:51+08:00",
"updated_at": "2024-09-27T14:58:51+08:00"
}
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
403 |
禁止访问 |
404 |
请求路径不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc