跳转至

创建仓库里程碑

POST /api/v5/repos/{owner}/{repo}/milestones

该接口用于在指定仓库中创建里程碑,支持设置里程碑标题、具体描述、截止日期及状态,并返回创建后的里程碑完整信息。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

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

Request Body:

请求体通过 JSON 或表单提交,JSON 请求需设置请求头 Content-Type: application/json.字段取值规则以源码为准.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "title": {
      "description": "里程碑标题",
      "type": "string",
      "minLength": 1
    },
    "description": {
      "description": "里程碑具体描述",
      "type": "string"
    },
    "due_on": {
      "description": "里程碑的截止日期",
      "type": "string",
      "format": "date",
      "minLength": 1
    },
    "state": {
      "description": "里程碑状态",
      "type": "string"
    }
  },
  "required": ["title", "due_on"]
}

响应参数

字段 类型 必返 可为空 说明
closed_issues integer 是 是 关闭的issue数量
created_at string 是 是 创建时间
description string 是 是 描述
due_on string 是 是 截止时间
html_url string 是 是 html地址
number integer 是 是 编号
id integer 是 是 id
open_issues integer 是 是 打开的issue数量
repository_id integer 是 是 仓库id
state string 是 是 状态
title string 是 是 标题
updated_at string 是 是 更新时间
url string 是 是 url

失败响应

除成功响应外,调用方还需了解失败时的返回形态,以便编写错误处理逻辑.

400 参数错误

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

401 未认证

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

403 无权限

{
  "error": "forbidden",
  "message": "您没有权限执行此操作"
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 请求参数错误或无法解析
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)

请求示例

参数说明

<owner> 替换为仓库所属空间地址(企业、组织或个人的地址 path);<repo> 替换为仓库路径(path);<token> 替换为你的 AtomGit 用户访问令牌.

cURL

curl -X POST 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/milestones?access_token=<token>' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "title": "里程碑标题",
    "description": "里程碑具体描述",
    "due_on": "2026-01-31"
  }'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
  "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/milestones?access_token=<token>",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Accept": "application/json"
    },
    body: JSON.stringify({
      title: "里程碑标题",
      description: "里程碑具体描述",
      due_on: "2026-01-31"
    })
  }
);

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>/milestones",
    params={"access_token": "<token>"},
    json={
        "title": "里程碑标题",
        "description": "里程碑具体描述",
        "due_on": "2026-01-31",
    },
    headers={
        "Accept": "application/json",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "closed_issues": 0,
  "created_at": "2024-10-08T10:58:16+08:00",
  "description": "你好中国",
  "due_on": "2024-11-08",
  "html_url": "https://api.atomgit.com/dengmengmian/oneapi/milestones/1",
  "number": 4914,
  "id": 4066481,
  "open_issues": 0,
  "repository_id": 4066481,
  "state": "active",
  "title": "你好中国",
  "updated_at": "2024-10-08T10:58:16+08:00",
  "url": "https://api.atomgit.com/dengmengmian/oneapi/milestones/1"
}

错误码

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

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