跳转至

创建Issue评论

POST /api/v5/repos/{owner}/{repo}/issues/{number}/comments

该接口用于在指定仓库的指定 Issue 下创建一条评论,通过提交评论内容完成评论创建,并返回新建评论的详细信息。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
owner path string 是 仓库所属空间地址(企业、组织或个人的地址 path)
repo path string 是 仓库路径(path)
number path integer 是 Issue 编号
access_token query string 是 用户授权码

Request Body:

请求体以 application/json 形式提交,包含评论内容 body(必填)。

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "body": {
      "description": "评论内容(The contents of the comment)",
      "type": "string",
      "minLength": 1
    }
  },
  "required": ["body"]
}

响应参数

字段 类型 必返 可为空 说明
id integer 是 否 评论 ID
body string 是 否 评论内容
user object 是 是 评论者的用户信息
target object 是 是 评论所属的目标对象
created_at string 否 是 评论创建时间
updated_at string 否 是 评论更新时间

user 对象

字段 类型 必返 可为空 说明
user.id string 是 否 用户 ID
user.login string 是 否 登录名
user.name string 是 否 用户名
user.type string 否 是 用户类型,如 User
user.avatar_url string 是 否 头像 URL
user.html_url string 是 否 用户主页 URL
user.member_role string 否 是 成员角色
user.remark string 否 是 企业备注名
user.events_url string 否 是 事件 URL
user.followers_url string 否 是 关注者 URL
user.following_url string 否 是 关注 URL
user.gists_url string 否 是 代码片段 URL
user.organizations_url string 否 是 组织 URL
user.received_events_url string 否 是 接收事件 URL
user.repos_url string 否 是 存储库 URL
user.starred_url string 否 是 收藏 URL
user.subscriptions_url string 否 是 订阅 URL
user.url string 否 是 用户 URL

target.issue 对象

字段 类型 必返 可为空 说明
target.issue.id integer 是 否 Issue ID
target.issue.title string 是 否 Issue 标题
target.issue.number integer 是 否 Issue 编号

失败响应

401 未认证

{
  "error": "unauthorized",
  "message": "缺少或无效的访问令牌"
}

404 资源不存在

{
  "error": "not_found",
  "message": "仓库或 Issue 不存在"
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
401 需要认证(Requires authentication)
404 资源不存在(Not found)

请求示例

参数说明

<owner> 替换为仓库所属空间地址(企业、组织或个人的地址 path); <repo> 替换为仓库路径(path); <number> 替换为 Issue 编号; <token> 替换为你的 AtomGit 用户访问令牌; <body> 替换为评论内容。

cURL

curl -X POST 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/issues/<number>/comments?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "body": "<body>"
  }'

JavaScript

const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/issues/<number>/comments?access_token=<token>", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Accept": "application/json",
  },
  body: JSON.stringify({
    body: "<body>",
  }),
});

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>/issues/<number>/comments",
    params={"access_token": "<token>"},
    headers={
        "Content-Type": "application/json",
        "Accept": "application/json",
    },
    json={"body": "<body>"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "id": 271624,
  "body": "评论内容。",
  "user": {
    "avatar_url": "https://api.atomgit.com/avatar.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
  },
  "target": {
    "issue": {
      "id": 152134,
      "title": "",
      "number": 1
    }
  },
  "created_at": null,
  "updated_at": null
}

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