跳转至

获取 pr 评论

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,取自路径中的评论 ID
discussion_id string 是 是 评论所属讨论 ID
body string 是 是 评论内容
comment_type string 是 是 评论类型,如 pr_comment 表示普通评论,diff_comment 表示代码差异评论
is_outdated boolean 是 是 检视意见是否已过时
created_at string 是 否 评论创建时间,格式 yyyy-MM-dd'T'HH:mm:ssXXX
updated_at string 是 否 评论更新时间,格式 yyyy-MM-dd'T'HH:mm:ssXXX
user object 否 是 评论作者;评论作者存在时才返回
position object 否 是 代码差异评论关联的行位置;源码位置信息存在时才有值

user 对象

字段 类型 必返 可为空 说明
user.id string 是 否 用户标识
user.object_id string 否 是 用户对象标识;用户中心能查到用户信息时才有值
user.login string 是 是 用户名
user.name string 是 是 用户昵称
user.type string 是 否 对象类型,恒为 User

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 否 是 差异位置类型
position.old_line integer 否 是 旧版本文件的结束行号
position.new_line integer 否 是 新版本文件的结束行号
position.start_old_line integer 否 是 旧版本文件的起始行号
position.start_new_line integer 否 是 新版本文件的起始行号

失败响应

评论不存在、仓库不可见或评论 ID 非法时,接口返回错误响应;错误响应体字段为 error_code、error_code_name、error_message。

404 评论或仓库不存在

{
  "error_code": 404,
  "error_code_name": "NOT_PATH",
  "error_message": "评论不存在"
}

400 参数错误

{
  "error_code": 400,
  "error_code_name": "BAD_REQUEST",
  "error_message": "参数类型错误"
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 请求参数错误(Bad Request)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 请求路径或资源不存在(Not Found)

请求示例

参数说明

<owner> 替换为仓库所属空间地址(企业、组织或个人的地址 path) 如果是三段命名空间,例如: gh_mirrors/co/QwenPaw。owner值为gh_mirrors/co,调用时必须把第一个 / 编码为 %2F,owner传值为: gh_mirrors%2Fco。

<repo> 替换为仓库路径(path);

<id> 替换为 Pull Request 评论 ID;

<token> 替换为你的 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": 1234567,
  "discussion_id": "5f8d0f0c1a2b3c4d5e6f7a8b",
  "body": "这里的空指针判断建议补充",
  "comment_type": "diff_comment",
  "is_outdated": false,
  "created_at": "2024-09-11T14:53:39+08:00",
  "updated_at": "2024-09-11T14:53:39+08:00",
  "user": {
    "id": "1234567",
    "object_id": "6982f866ff100269e77468bc",
    "login": "octocat",
    "name": "Octo Cat",
    "type": "User"
  },
  "position": {
    "base_sha": "0f3c1a8c9d2b4e5f6a7b8c9d0e1f2a3b4c5d6e7f",
    "start_sha": "0f3c1a8c9d2b4e5f6a7b8c9d0e1f2a3b4c5d6e7f",
    "head_sha": "1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b",
    "old_path": "src/main/java/com/example/Demo.java",
    "new_path": "src/main/java/com/example/Demo.java",
    "position_type": "text",
    "old_line": 42,
    "new_line": 43,
    "start_old_line": 40,
    "start_new_line": 41
  }
}

错误码

错误码 说明
400 参数错误或请求无法解析
401 未认证或凭证无效(缺少/无效的访问凭证)
403 无权限访问该资源
404 评论或仓库不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc