创建Issue¶
POST /api/v5/repos/{owner}/issues
用户调用此接口,在指定仓库下创建一个 Issue。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(组织或个人的地址 path) |
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"
},
"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"
},
"template_path": {
"description": "issue模板路径,项目模板支持.gitcode,.github,.gitee目录下的文件,组织模板仅支持.gitcode项目下的.gitcode目录下的文件",
"type": "string"
},
"issue_type": {
"description": "issue类型(企业版支持),设置值需与企业issue高级功能中的设置保持一致",
"type": "string"
},
"issue_severity": {
"description": "issue优先级(企业版支持),设置值需与企业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", "body"]
}
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
id |
integer | 是 | 否 | Issue 的 ID |
html_url |
string | 是 | 否 | Issue 的 HTML 地址 |
number |
integer | 是 | 否 | Issue 编号 |
state |
string | 是 | 否 | Issue 状态,如 opened |
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 |
array | 是 | 是 | 标签列表,可能为 null |
stage |
string | 是 | 是 | Issue 所处阶段 |
severity |
string | 是 | 是 | Issue 优先级(严重程度) |
custom_fields |
array | 否 | 是 | 自定义字段信息 |
user 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
user.avatar_url |
string | 是 | 否 | 用户头像地址 |
user.events_url |
string | 否 | 是 | 事件地址,可能为 null |
user.followers_url |
string | 否 | 是 | 关注者地址,可能为 null |
user.following_url |
string | 否 | 是 | 正在关注地址,可能为 null |
user.gists_url |
string | 否 | 是 | 代码片段地址,可能为 null |
user.html_url |
string | 是 | 否 | 用户主页地址 |
user.id |
string | 是 | 否 | 用户 ID |
user.login |
string | 是 | 否 | 登录名 |
user.member_role |
string | 否 | 是 | 成员角色,可能为 null |
user.name |
string | 是 | 否 | 用户昵称 |
user.organizations_url |
string | 否 | 是 | 组织地址,可能为 null |
user.received_events_url |
string | 否 | 是 | 接收事件地址,可能为 null |
user.remark |
string | 否 | 是 | 备注,可能为 null |
user.repos_url |
string | 否 | 是 | 仓库列表地址,可能为 null |
user.starred_url |
string | 否 | 是 | 星标地址,可能为 null |
user.subscriptions_url |
string | 否 | 是 | 订阅地址,可能为 null |
user.type |
string | 否 | 是 | 用户类型,可能为 null |
user.url |
string | 否 | 是 | 用户地址,可能为 null |
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 | 是 | 否 | 标签颜色 |
labels[].created_at |
string | 是 | 否 | 标签创建时间 |
labels[].updated_at |
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) |
400 |
参数错误(Bad Request) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
资源不存在(Not Found) |
请求示例¶
参数说明¶
以下示例可直接复制调用:<owner> 替换为仓库所属空间地址(组织或个人的地址 path);<repo> 替换为仓库路径(owner 对应空间下仓库的 path);<token> 替换为你的 AtomGit 用户访问令牌。示例中除必填字段(repo、title、body)外,还展示了常用可选字段。
cURL¶
curl -X POST 'https://api.atomgit.com/api/v5/repos/<owner>/issues?access_token=<token>' \
-H 'Content-Type: application/json' \
-d '{
"repo": "<repo>",
"title": "<issue title>",
"body": "<issue description>",
"assignee": "user1,user2",
"milestone": 3,
"labels": "bug,performance",
"security_hole": "false"
}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/issues?access_token=<token>", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
repo: "<repo>",
title: "<issue title>",
body: "<issue description>",
assignee: "user1,user2",
labels: "bug,performance",
}),
});
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>/issues",
params={"access_token": "<token>"},
json={
"repo": "<repo>",
"title": "<issue title>",
"body": "<issue description>",
"assignee": "user1,user2",
"labels": "bug,performance",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"id": 152642,
"html_url": "https://api.atomgit.com/dengmengmian/test01/issues/15",
"number": 15,
"state": "opened",
"title": "半月据",
"body": "节油料被引系活力级少本化段维家住实。",
"user": {
"avatar_url": "https://api.atomgit.com/avatars/dengmengmian.png",
"html_url": "https://api.atomgit.com/dengmengmian",
"id": "661ce4eab470b1430d456154",
"login": "dengmengmian",
"name": "麻凡_"
},
"assignee": null,
"repository": {
"id": 152642,
"full_name": "dengmengmian/test01",
"path": "test01",
"name": "test01",
"description": "",
"created_at": "2024-04-18T14:35:15.479+08:00",
"updated_at": "2024-04-18T14:35:15.479+08:00"
},
"created_at": "2024-04-18T14:35:15.479+08:00",
"updated_at": "2024-04-18T14:35:15.479+08:00",
"finished_at": null,
"labels": [
{
"id": 382379,
"name": "enim",
"color": "#428BCA"
},
{
"id": 382378,
"name": "proident",
"color": "#428BCA"
}
],
"stage": "New",
"severity": "Major"
}
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc