获取pr关联的issue¶
GET /api/v5/repos/{owner}/{repo}/pulls/{number}/issues
该接口用于获取指定仓库中某个 PR(Pull Request)所关联的 issue 列表,并返回每个 issue 的编号、标题、状态、内容描述、创建者信息、标签列表以及创建、更新、关闭时间等详细数据。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(企业、组织或个人的地址 path) |
repo |
path | string | 是 | 仓库路径(path) |
number |
path | integer | 是 | 第几个 PR,即本仓库 PR 的序数 |
access_token |
query | string | 否 | 用户授权码 |
page |
query | integer | 否 | 当前的页码,默认为 1 |
per_page |
query | integer | 否 | 每页的数量,最大为 100,默认 20 |
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
number |
string | 是 | — | issue 编号 |
title |
string | 是 | — | issue 标题 |
state |
string | 是 | — | issue 状态 |
url |
string | 是 | — | issue 的 API 地址 |
body |
string | 是 | — | issue 内容描述 |
user |
object | 是 | — | 创建该 issue 的用户信息 |
labels |
object[] | 是 | — | issue 的标签列表 |
issue_created_at |
string | 是 | 否 | issue 创建时间 |
issue_updated_at |
string | 是 | 否 | issue 更新时间 |
issue_closed_at |
string | 是 | 是 | issue 关闭时间,未关闭时为 null |
Note: 响应体为 issue 对象数组,上表描述的是数组中每个元素的结构。
user 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
user.id |
string | 是 | — | 用户 ID |
user.login |
string | 是 | — | 用户登录名 |
user.name |
string | 是 | — | 用户名称 |
labels 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
labels.id |
integer | 是 | — | 标签 ID |
labels.name |
string | 是 | — | 标签名称 |
labels.color |
string | 是 | — | 标签颜色 |
labels.created_at |
string | 是 | — | 标签添加时间 |
labels.updated_at |
string | 是 | — | 标签更新时间 |
失败响应¶
除成功响应外,调用方还需要了解失败场景的返回形态,以便编写错误处理逻辑。以下错误响应形态为通用约定,错误字段名以后端实际返回为准。
400 参数错误
401 未认证
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
资源不存在(Not found) |
405 |
请求方法不支持(Method not allowed) |
429 |
请求过于频繁,触发限流(Too many requests) |
500 |
系统内部错误(Internal server error) |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(企业、组织或个人的地址 path);<repo>替换为仓库路径(path);<number>替换为 PR 序号(第几个 PR,即本仓库 PR 的序数);<token>替换为你的 AtomGit 用户访问令牌(本接口允许匿名访问,令牌为可选参数)。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/issues?page=1&per_page=20' \
-H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/issues?page=1&per_page=20", {
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>/issues",
params={"page": 1, "per_page": 20},
headers={
"Accept": "application/json",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
Note: 本接口允许匿名访问,也可携带 access_token(?access_token=<token>)获取授权可见的完整数据。
响应示例¶
状态码: 200
[
{
"number": "1",
"title": "进行稳定性测试",
"state": "open",
"url": "https://api.atomgit.com/api/v5/repos/sytest/paopao/issues/1",
"body": "发生什么问题了?",
"user": {
"id": "681",
"login": "test",
"name": "test"
},
"labels": [
{
"id": 381445,
"name": "help wanted",
"color": "#008672",
"created_at": "2024-01-01T09:00:00Z",
"updated_at": "2024-01-01T09:00:00Z"
}
],
"issue_created_at": "2024-01-01T10:00:00Z",
"issue_updated_at": "2024-01-02T10:00:00Z",
"issue_closed_at": null
}
]
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
400 |
参数错误或请求无法解析 |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc