更新Issue¶
PATCH /api/v5/repos/{owner}/issues/{number}
用户调用此接口,更新指定仓库中的 Issue。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(组织或个人的地址 path) |
number |
path | string | 是 | 第几个 issue,即本仓库 issue 的序数 |
access_token |
query | string | 是 | 用户授权码 |
Request Body:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"repo": {
"description": "仓库路径",
"type": "string"
},
"title": {
"description": "Issue标题",
"type": "string"
},
"body": {
"description": "Issue描述",
"type": "string"
},
"state": {
"description": "Issue 状态:reopen(开启)、close(关闭)",
"type": "string",
"enum": ["reopen", "close"]
},
"assignee": {
"description": "Issue 负责人的 username,多个用英文逗号隔开",
"type": "string"
},
"milestone": {
"description": "里程碑序号",
"type": "integer"
},
"labels": {
"description": "用逗号分开的标签,名称要求长度在 2-20 之间且非特殊字符。如: bug,performance",
"type": "string"
},
"security_hole": {
"description": "是否为私有 Issue(默认为 false)",
"type": "string",
"default": "false"
},
"status": {
"description": "Issue 状态(企业版支持),与 issue_type 不能同时设置",
"type": "string"
},
"issue_severity": {
"description": "Issue 优先级(企业版支持),与 issue_type 不能同时设置",
"type": "string"
},
"issue_type": {
"description": "Issue 类型(企业版支持),与状态和优先级不能同时设置",
"type": "string"
},
"custom_fields": {
"description": "自定义字段信息(企业版支持)",
"type": "array",
"items": {
"type": "object",
"properties": {
"field_name": {
"description": "字段名称",
"type": "string"
},
"field_values": {
"description": "字段的值数组",
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"required": ["repo", "title"]
}
Note: status 与 issue_severity 可同时设置,但二者均不能与 issue_type 同时设置(企业版支持)。
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
id |
integer | 是 | 否 | Issue ID |
html_url |
string | 是 | 否 | Issue 的网页地址 |
number |
integer | 是 | 否 | Issue 序号 |
state |
string | 是 | 否 | Issue 状态 |
title |
string | 是 | 否 | Issue 标题 |
body |
string | 是 | 是 | Issue 描述 |
user |
object | 是 | 否 | Issue 创建者信息 |
assignee |
object | 否 | 是 | Issue 负责人信息,可能为 null |
repository |
object | 是 | 否 | 所属仓库信息 |
created_at |
string | 是 | 否 | 创建时间 |
updated_at |
string | 是 | 否 | 更新时间 |
finished_at |
string | 否 | 是 | 完成时间,可能为 null |
labels |
object[] | 是 | 是 | Issue 标签列表 |
stage |
string | 是 | 是 | 阶段 |
severity |
string | 是 | 是 | 严重程度 |
custom_fields |
object[] | 是 | 是 | 自定义字段信息(企业版支持) |
user 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
user.avatar_url |
string | 是 | 是 | 头像地址 |
user.events_url |
string | 否 | 是 | 事件地址 |
user.followers_url |
string | 否 | 是 | 关注者列表地址 |
user.following_url |
string | 否 | 是 | 正在关注列表地址 |
user.gists_url |
string | 否 | 是 | 代码片段列表地址 |
user.html_url |
string | 是 | 否 | 用户主页地址 |
user.id |
string | 是 | 否 | 用户 ID |
user.login |
string | 是 | 否 | 登录名 |
user.member_role |
string | 否 | 是 | 成员角色 |
user.name |
string | 是 | 否 | 姓名 |
user.organizations_url |
string | 否 | 是 | 组织列表地址 |
user.received_events_url |
string | 否 | 是 | 接收事件列表地址 |
user.remark |
string | 否 | 是 | 备注 |
user.repos_url |
string | 否 | 是 | 仓库列表地址 |
user.starred_url |
string | 否 | 是 | 星标仓库列表地址 |
user.subscriptions_url |
string | 否 | 是 | 订阅列表地址 |
user.type |
string | 否 | 是 | 用户类型 |
user.url |
string | 否 | 是 | 用户地址 |
assignee 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
assignee.avatar_url |
string | 是 | 是 | 头像地址 |
assignee.events_url |
string | 否 | 是 | 事件地址 |
assignee.followers_url |
string | 否 | 是 | 关注者列表地址 |
assignee.following_url |
string | 否 | 是 | 正在关注列表地址 |
assignee.gists_url |
string | 否 | 是 | 代码片段列表地址 |
assignee.html_url |
string | 是 | 否 | 用户主页地址 |
assignee.id |
string | 是 | 否 | 用户 ID |
assignee.login |
string | 是 | 否 | 登录名 |
assignee.member_role |
string | 否 | 是 | 成员角色 |
assignee.name |
string | 是 | 否 | 姓名 |
assignee.organizations_url |
string | 否 | 是 | 组织列表地址 |
assignee.received_events_url |
string | 否 | 是 | 接收事件列表地址 |
assignee.remark |
string | 否 | 是 | 备注 |
assignee.repos_url |
string | 否 | 是 | 仓库列表地址 |
assignee.starred_url |
string | 否 | 是 | 星标仓库列表地址 |
assignee.subscriptions_url |
string | 否 | 是 | 订阅列表地址 |
assignee.type |
string | 否 | 是 | 用户类型 |
assignee.url |
string | 否 | 是 | 用户地址 |
repository 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
repository.id |
integer | 是 | 否 | 仓库 ID |
repository.full_name |
string | 是 | 否 | 仓库全名(owner/repo) |
repository.path |
string | 是 | 否 | 仓库路径 |
repository.name |
string | 是 | 否 | 仓库名称 |
repository.description |
string | 是 | 是 | 仓库描述 |
repository.created_at |
string | 是 | 否 | 仓库创建时间 |
repository.updated_at |
string | 是 | 否 | 仓库更新时间 |
labels[] 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
labels.id |
integer | 是 | 否 | 标签 ID |
labels.name |
string | 是 | 否 | 标签名称 |
labels.color |
string | 是 | 否 | 标签颜色 |
custom_fields[] 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
custom_fields.field_name |
string | 是 | 否 | 自定义字段名称 |
custom_fields.field_type |
string | 是 | 否 | 自定义字段的类型。text_single:单行文本,text_multi:多行文本,integer:整数,decimal:小数,date:日期,select_single:单选下拉,select_multi:多选下拉,member_single:单选成员,member_multi:多选成员 |
custom_fields.field_visibility |
string | 是 | 否 | 可见性。0:仅管理员可见,1:所有人可见 |
custom_fields.field_values |
string[] | 是 | 否 | 自定义字段的值 |
失败响应¶
调用方需要知道失败响应的形态才能编写错误处理。下面仅列出该接口可能出现的通用失败场景,错误字段名以后端实际返回为准。
400 参数错误
401 未认证
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
资源不存在(Not found) |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(组织或个人的地址 path);<number>替换为 Issue 序号;<token>替换为你的 AtomGit 用户访问令牌;<username>替换为 Issue 负责人的 username。
cURL¶
curl -X PATCH 'https://api.atomgit.com/api/v5/repos/<owner>/issues/<number>?access_token=<token>' -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{
"repo": "test01",
"title": "修复登录超时问题",
"body": "更新 Issue 描述内容",
"state": "close",
"assignee": "<username>",
"labels": "bug,performance"
}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
"https://api.atomgit.com/api/v5/repos/<owner>/issues/<number>?access_token=<token>",
{
method: "PATCH",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
repo: "test01",
title: "修复登录超时问题",
body: "更新 Issue 描述内容",
state: "close",
assignee: "<username>",
labels: "bug,performance",
}),
}
);
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.patch(
"https://api.atomgit.com/api/v5/repos/<owner>/issues/<number>",
params={"access_token": "<token>"},
json={
"repo": "test01",
"title": "修复登录超时问题",
"body": "更新 Issue 描述内容",
"state": "close",
"assignee": "<username>",
"labels": "bug,performance",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"id": 152467,
"html_url": "https://api.atomgit.com/dengmengmian/test01/issues/14",
"number": 14,
"state": "closed",
"title": "修复登录超时问题",
"body": "更新后的 Issue 描述",
"user": {
"avatar_url": "https://api.atomgit.com/avatar/example.png",
"events_url": null,
"followers_url": null,
"following_url": null,
"gists_url": null,
"html_url": "https://api.atomgit.com/dengmengmian",
"id": "661ce4eab470b1430d456154",
"login": "dengmengmian",
"member_role": null,
"name": "麻凡_",
"organizations_url": null,
"received_events_url": null,
"remark": null,
"repos_url": null,
"starred_url": null,
"subscriptions_url": null,
"type": null,
"url": null
},
"assignee": {
"avatar_url": "https://api.atomgit.com/avatar/example.png",
"events_url": null,
"followers_url": null,
"following_url": null,
"gists_url": null,
"html_url": "https://api.atomgit.com/dengmengmian",
"id": "661ce4eab470b1430d456154",
"login": "dengmengmian",
"member_role": null,
"name": "麻凡_",
"organizations_url": null,
"received_events_url": null,
"remark": null,
"repos_url": null,
"starred_url": null,
"subscriptions_url": null,
"type": null,
"url": null
},
"repository": {
"id": 152467,
"full_name": "dengmengmian/test01",
"path": "test01",
"name": "test01",
"description": "",
"created_at": "2024-04-16T14:38:43.464+08:00",
"updated_at": "2024-04-18T18:27:21.955+08:00"
},
"created_at": "2024-04-16T14:38:43.464+08:00",
"updated_at": "2024-04-18T18:27:21.955+08:00",
"finished_at": "2024-04-16T14:49:45.166+08:00",
"labels": [
{
"id": 382389,
"name": "bug",
"color": "#428BCA"
},
{
"id": 382388,
"name": "performance",
"color": "#428BCA"
}
],
"stage": "New",
"severity": "Major",
"custom_fields": [
{
"field_name": "priority",
"field_type": "select_single",
"field_visibility": "1",
"field_values": ["High"]
}
]
}
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
400 |
参数错误或请求无法解析 |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc