指派用户测试 Pull Request¶
POST /api/v5/repos/{owner}/{repo}/pulls/{number}/testers
该接口用于为指定仓库中的某个 Pull Request 指派测试人,通过请求体中的测试人列表进行设置,并支持覆盖更新或新增测试人(由 add 参数控制),操作成功后返回当前的测试人用户信息列表。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(组织或个人的地址 path) |
repo |
path | string | 是 | 仓库路径(path) |
number |
path | integer | 是 | 第几个 PR,即本仓库 PR 的序数 |
access_token |
query | string | 是 | 用户授权码 |
Request Body:
请求体为 JSON 对象,字段说明如下:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"testers": {
"description": "用户的个人空间地址,以逗号分隔",
"type": "string"
},
"add": {
"description": "是否新增测试人,为 true 会新增测试人,而不是覆盖,默认 false",
"type": "boolean",
"default": false
}
},
"required": ["testers"]
}
响应参数¶
响应为数组,每个元素为一个测试人(用户)对象。
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
id |
integer | 是 | 否 | 用户 ID |
login |
string | 是 | 否 | 用户名(登录名) |
name |
string | 是 | 是 | 用户昵称 |
avatar_url |
string | 是 | 是 | 用户头像地址 |
user 对象
数组中每个测试人对象还可能包含以下字段(以实际返回为准):
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
url |
string | 否 | 是 | 用户主页地址 |
html_url |
string | 否 | 是 | 用户 HTML 主页地址 |
remark |
string | 否 | 是 | 备注 |
followers_url |
string | 否 | 是 | 关注者列表地址 |
following_url |
string | 否 | 是 | 正在关注列表地址 |
gists_url |
string | 否 | 是 | Gists 列表地址 |
starred_url |
string | 否 | 是 | 收藏列表地址 |
subscriptions_url |
string | 否 | 是 | 订阅列表地址 |
organizations_url |
string | 否 | 是 | 所属组织列表地址 |
repos_url |
string | 否 | 是 | 仓库列表地址 |
events_url |
string | 否 | 是 | 事件列表地址 |
received_events_url |
string | 否 | 是 | 收到的事件列表地址 |
type |
string | 否 | 是 | 用户类型 |
permission |
string | 否 | 是 | 权限 |
object_id |
string | 否 | 是 | 对象 ID |
email |
string | 否 | 是 | 邮箱 |
失败响应¶
400 参数错误
401 未认证
404 资源不存在
错误字段名以后端实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
资源不存在(Not found) |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(组织或个人的地址 path);<repo>替换为仓库路径(path);<number>替换为 PR 序数;<token>替换为你的 AtomGit 用户访问令牌。
cURL¶
curl -X POST 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/testers?access_token=<token>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"testers": "username1,username2", "add": true}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/testers?access_token=<token>", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
testers: "username1,username2",
add: true,
}),
});
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.post(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/testers",
params={"access_token": "<token>"},
json={
"testers": "username1,username2",
"add": True,
},
headers={"Accept": "application/json"},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
[
{
"id": 43,
"login": "green",
"name": "green",
"avatar_url": "https://api.atomgit.com/avatar.png"
},
{
"id": 452,
"login": "zhanghq2",
"name": "zhanghq2",
"avatar_url": "https://api.atomgit.com/avatar.png"
}
]
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
400 |
参数错误或请求无法解析 |
404 |
请求路径不存在或资源不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc