跳到主要内容
REST API 现在已版本化。 更多信息,请参阅“关于 API 版本控制”。

里程碑的 REST API 端点

使用 REST API 管理里程碑。

列出里程碑

列出某个代码库的里程碑。

“列出里程碑”的细粒度访问令牌

此端点可以使用以下细粒度令牌类型:

细粒度令牌必须至少具有以下权限集之一

  • “问题”代码库权限(读取)
  • “拉取请求”代码库权限(读取)

如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。

“列出里程碑”的参数

标头
名称、类型、描述
accept 字符串

建议设置为application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必填

代码库的帐户所有者。名称不区分大小写。

repo 字符串 必填

不带.git扩展名的代码库名称。名称不区分大小写。

查询参数
名称、类型、描述
state 字符串

里程碑的状态。可以是openclosedall

默认值:open

可以是:openclosedall

sort 字符串

排序结果的依据。可以是due_oncompleteness

默认值:due_on

可以是:due_oncompleteness

direction 字符串

排序的方向。可以是ascdesc

默认值:asc

可以是:ascdesc

per_page 整数

每页的结果数(最大 100)。更多信息,请参阅“REST API 中的分页使用”。

默认值:30

page 整数

要获取的结果的页码。更多信息,请参阅“REST API 中的分页使用”。

默认值:1

“列出里程碑”的 HTTP 响应状态码

状态码描述
200

OK

404

资源未找到

“列出里程碑”的代码示例

请求示例

get/repos/{owner}/{repo}/milestones
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/milestones

响应

状态:200
[ { "url": "https://api.github.com/repos/octocat/Hello-World/milestones/1", "html_url": "https://github.com/octocat/Hello-World/milestones/v1.0", "labels_url": "https://api.github.com/repos/octocat/Hello-World/milestones/1/labels", "id": 1002604, "node_id": "MDk6TWlsZXN0b25lMTAwMjYwNA==", "number": 1, "state": "open", "title": "v1.0", "description": "Tracking milestone for version 1.0", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "open_issues": 4, "closed_issues": 8, "created_at": "2011-04-10T20:09:31Z", "updated_at": "2014-03-03T18:58:10Z", "closed_at": "2013-02-12T13:22:01Z", "due_on": "2012-10-09T23:39:01Z" } ]

创建里程碑

创建里程碑。

“创建里程碑”的细粒度访问令牌

此端点可以使用以下细粒度令牌类型:

细粒度令牌必须至少具有以下权限集之一

  • “问题”代码库权限(写入)
  • “拉取请求”代码库权限(写入)

“创建里程碑”的参数

标头
名称、类型、描述
accept 字符串

建议设置为application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必填

代码库的帐户所有者。名称不区分大小写。

repo 字符串 必填

不带.git扩展名的代码库名称。名称不区分大小写。

正文参数
名称、类型、描述
title 字符串 必填

里程碑的标题。

state 字符串

里程碑的状态。可以是openclosed

默认值:open

可以是:openclosed

description 字符串

里程碑的描述。

due_on 字符串

里程碑的截止日期。这是 ISO 8601 格式的时间戳:YYYY-MM-DDTHH:MM:SSZ

“创建里程碑”的 HTTP 响应状态码

状态码描述
201

已创建

404

资源未找到

422

验证失败,或端点已被垃圾信息滥用。

“创建里程碑”的代码示例

请求示例

post/repos/{owner}/{repo}/milestones
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/milestones \ -d '{"title":"v1.0","state":"open","description":"Tracking milestone for version 1.0","due_on":"2012-10-09T23:39:01Z"}'

响应

状态:201
{ "url": "https://api.github.com/repos/octocat/Hello-World/milestones/1", "html_url": "https://github.com/octocat/Hello-World/milestones/v1.0", "labels_url": "https://api.github.com/repos/octocat/Hello-World/milestones/1/labels", "id": 1002604, "node_id": "MDk6TWlsZXN0b25lMTAwMjYwNA==", "number": 1, "state": "open", "title": "v1.0", "description": "Tracking milestone for version 1.0", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "open_issues": 4, "closed_issues": 8, "created_at": "2011-04-10T20:09:31Z", "updated_at": "2014-03-03T18:58:10Z", "closed_at": "2013-02-12T13:22:01Z", "due_on": "2012-10-09T23:39:01Z" }

获取里程碑

使用给定的里程碑编号获取里程碑。

“获取里程碑”的细粒度访问令牌

此端点可以使用以下细粒度令牌类型:

细粒度令牌必须至少具有以下权限集之一

  • “问题”代码库权限(读取)
  • “拉取请求”代码库权限(读取)

如果仅请求公共资源,则无需身份验证或上述权限即可使用此端点。

“获取里程碑”的参数

标头
名称、类型、描述
accept 字符串

建议设置为application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必填

代码库的帐户所有者。名称不区分大小写。

repo 字符串 必填

不带.git扩展名的代码库名称。名称不区分大小写。

milestone_number 整数 必填

标识里程碑的编号。

获取里程碑的HTTP响应状态码

状态码描述
200

OK

404

资源未找到

获取里程碑的代码示例

请求示例

get/repos/{owner}/{repo}/milestones/{milestone_number}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/milestones/MILESTONE_NUMBER

响应

状态:200
{ "url": "https://api.github.com/repos/octocat/Hello-World/milestones/1", "html_url": "https://github.com/octocat/Hello-World/milestones/v1.0", "labels_url": "https://api.github.com/repos/octocat/Hello-World/milestones/1/labels", "id": 1002604, "node_id": "MDk6TWlsZXN0b25lMTAwMjYwNA==", "number": 1, "state": "open", "title": "v1.0", "description": "Tracking milestone for version 1.0", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "open_issues": 4, "closed_issues": 8, "created_at": "2011-04-10T20:09:31Z", "updated_at": "2014-03-03T18:58:10Z", "closed_at": "2013-02-12T13:22:01Z", "due_on": "2012-10-09T23:39:01Z" }

更新里程碑

更新里程碑的细粒度访问令牌

此端点可以使用以下细粒度令牌类型:

细粒度令牌必须至少具有以下权限集之一

  • “问题”代码库权限(写入)
  • “拉取请求”代码库权限(写入)

更新里程碑的参数

标头
名称、类型、描述
accept 字符串

建议设置为application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必填

代码库的帐户所有者。名称不区分大小写。

repo 字符串 必填

不带.git扩展名的代码库名称。名称不区分大小写。

milestone_number 整数 必填

标识里程碑的编号。

正文参数
名称、类型、描述
title 字符串

里程碑的标题。

state 字符串

里程碑的状态。可以是openclosed

默认值:open

可以是:openclosed

description 字符串

里程碑的描述。

due_on 字符串

里程碑的截止日期。这是 ISO 8601 格式的时间戳:YYYY-MM-DDTHH:MM:SSZ

更新里程碑的HTTP响应状态码

状态码描述
200

OK

更新里程碑的代码示例

请求示例

patch/repos/{owner}/{repo}/milestones/{milestone_number}
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/milestones/MILESTONE_NUMBER \ -d '{"title":"v1.0","state":"open","description":"Tracking milestone for version 1.0","due_on":"2012-10-09T23:39:01Z"}'

响应

状态:200
{ "url": "https://api.github.com/repos/octocat/Hello-World/milestones/1", "html_url": "https://github.com/octocat/Hello-World/milestones/v1.0", "labels_url": "https://api.github.com/repos/octocat/Hello-World/milestones/1/labels", "id": 1002604, "node_id": "MDk6TWlsZXN0b25lMTAwMjYwNA==", "number": 1, "state": "open", "title": "v1.0", "description": "Tracking milestone for version 1.0", "creator": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "open_issues": 4, "closed_issues": 8, "created_at": "2011-04-10T20:09:31Z", "updated_at": "2014-03-03T18:58:10Z", "closed_at": "2013-02-12T13:22:01Z", "due_on": "2012-10-09T23:39:01Z" }

删除里程碑

使用给定的里程碑编号删除里程碑。

删除里程碑的细粒度访问令牌

此端点可以使用以下细粒度令牌类型:

细粒度令牌必须至少具有以下权限集之一

  • “问题”代码库权限(写入)
  • “拉取请求”代码库权限(写入)

删除里程碑的参数

标头
名称、类型、描述
accept 字符串

建议设置为application/vnd.github+json

路径参数
名称、类型、描述
owner 字符串 必填

代码库的帐户所有者。名称不区分大小写。

repo 字符串 必填

不带.git扩展名的代码库名称。名称不区分大小写。

milestone_number 整数 必填

标识里程碑的编号。

删除里程碑的HTTP响应状态码

状态码描述
204

无内容

404

资源未找到

删除里程碑的代码示例

请求示例

delete/repos/{owner}/{repo}/milestones/{milestone_number}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/milestones/MILESTONE_NUMBER

响应

状态:204