跳转至

创建commit评论

POST /api/v5/repos/{owner}/{repo}/commits/{sha}/comments

该接口用于在指定仓库的某个 commit 下创建评论,调用时需提供仓库所属空间、仓库路径及 commit ID,并提交评论内容,创建成功后返回评论 ID、内容及创建和更新时间等基本信息。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
owner path string 是 仓库所属空间地址(组织或个人的地址path)
repo path string 是 仓库路径(path)
sha path string 是 commit的id
access_token query string 是 用户授权码

Request Body:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "body": {
      "description": "评论内容",
      "type": "string"
    }
  },
  "required": ["body"]
}

响应参数

字段 类型 必返 可为空 说明
id string 是 否 评论id
body string 是 否 评论内容
created_at string 是 否 创建时间
updated_at string 是 否 更新时间

失败响应

只有 200/成功响应是不够的:调用方需要知道失败长什么样才能写错误处理。

400 参数错误

{
  "error": "invalid_request",
  "message": "参数 body 不能为空",
  "field": "body"
}

401 未认证

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

错误字段名以后端实际返回为准,以上示例仅作参考。

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad request)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 资源不存在(Not found)
500 系统内部错误(Internal server error)

请求示例

参数说明

示例中的占位符需替换为实际值:<owner> 为仓库所属空间地址(组织或个人的地址path);<repo> 为仓库路径(path);<sha> 为 commit 的 id;<token> 为你的 AtomGit 用户访问令牌;<body> 为评论内容。

cURL

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

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
  "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/commits/<sha>/comments?access_token=<token>",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Accept": "application/json",
    },
    body: JSON.stringify({ 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>/commits/<sha>/comments?access_token=<token>",
    headers={
        "Content-Type": "application/json",
        "Accept": "application/json",
    },
    json={"body": "评论内容"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "id": "12312sadsa",
  "body": "content",
  "created_at": "2024-03-28T11:19:33+08:00",
  "updated_at": "2024-03-28T11:19:33+08:00"
}

错误码

错误码 说明
401 未认证或凭证无效(缺少/无效的访问凭证)
400 参数错误或请求无法解析
404 请求路径不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

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