适用于标签的 REST API 终结点
使用 REST API 管理存储库、议题和拉取请求的标签。
关于标签
可以使用 REST API 管理存储库的标签,以及在议题和拉取请求中添加或删除标签。 每个拉取请求都是一个议题,但并非每个议题都是拉取请求。 因此,“问题”终结点中为这两项功能提供了“共享”操作,如操作代理人、标签和里程碑。
List labels for an issue
Lists all labels for an issue.
“List labels for an issue”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (read)
- "Pull requests" repository permissions (read)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。
“List labels for an issue”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
issue_number integer 必须The number that identifies the issue. |
名称, 类型, 说明 |
---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." 默认: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." 默认: |
“List labels for an issue”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
301 | Moved permanently |
404 | Resource not found |
410 | Gone |
“List labels for an issue”的示例代码
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels
Response
Status: 200
[
{
"id": 208045946,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDY=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/bug",
"name": "bug",
"description": "Something isn't working",
"color": "f29513",
"default": true
},
{
"id": 208045947,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDc=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/enhancement",
"name": "enhancement",
"description": "New feature or request",
"color": "a2eeef",
"default": false
}
]
Add labels to an issue
Adds labels to an issue. If you provide an empty array of labels, all labels are removed from the issue.
“Add labels to an issue”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (write)
- "Pull requests" repository permissions (write)
“Add labels to an issue”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
issue_number integer 必须The number that identifies the issue. |
名称, 类型, 说明 |
---|
labels array of strings The names of the labels to add to the issue's existing labels. You can pass an empty array to remove all labels. Alternatively, you can pass a single label as a |
“Add labels to an issue”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
301 | Moved permanently |
404 | Resource not found |
410 | Gone |
422 | Validation failed, or the endpoint has been spammed. |
“Add labels to an issue”的示例代码
请求示例
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels \
-d '{"labels":["bug","enhancement"]}'
Response
Status: 200
[
{
"id": 208045946,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDY=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/bug",
"name": "bug",
"description": "Something isn't working",
"color": "f29513",
"default": true
},
{
"id": 208045947,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDc=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/enhancement",
"name": "enhancement",
"description": "New feature or request",
"color": "a2eeef",
"default": false
}
]
Set labels for an issue
Removes any previous labels and sets the new labels for an issue.
“Set labels for an issue”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (write)
- "Pull requests" repository permissions (write)
“Set labels for an issue”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
issue_number integer 必须The number that identifies the issue. |
名称, 类型, 说明 |
---|
labels array of strings The names of the labels to set for the issue. The labels you set replace any existing labels. You can pass an empty array to remove all labels. Alternatively, you can pass a single label as a |
“Set labels for an issue”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
301 | Moved permanently |
404 | Resource not found |
410 | Gone |
422 | Validation failed, or the endpoint has been spammed. |
“Set labels for an issue”的示例代码
请求示例
curl -L \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels \
-d '{"labels":["bug","enhancement"]}'
Response
Status: 200
[
{
"id": 208045946,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDY=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/bug",
"name": "bug",
"description": "Something isn't working",
"color": "f29513",
"default": true
},
{
"id": 208045947,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDc=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/enhancement",
"name": "enhancement",
"description": "New feature or request",
"color": "a2eeef",
"default": false
}
]
Remove all labels from an issue
Removes all labels from an issue.
“Remove all labels from an issue”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (write)
- "Pull requests" repository permissions (write)
“Remove all labels from an issue”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
issue_number integer 必须The number that identifies the issue. |
“Remove all labels from an issue”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
204 | No Content |
301 | Moved permanently |
404 | Resource not found |
410 | Gone |
“Remove all labels from an issue”的示例代码
请求示例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels
Response
Status: 204
Remove a label from an issue
Removes the specified label from the issue, and returns the remaining labels on the issue. This endpoint returns a 404 Not Found
status if the label does not exist.
“Remove a label from an issue”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (write)
- "Pull requests" repository permissions (write)
“Remove a label from an issue”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
issue_number integer 必须The number that identifies the issue. |
name string 必须 |
“Remove a label from an issue”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
301 | Moved permanently |
404 | Resource not found |
410 | Gone |
“Remove a label from an issue”的示例代码
请求示例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels/NAME
Response
List labels for a repository
Lists all labels for a repository.
“List labels for a repository”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (read)
- "Pull requests" repository permissions (read)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。
“List labels for a repository”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
名称, 类型, 说明 |
---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." 默认: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." 默认: |
“List labels for a repository”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
404 | Resource not found |
“List labels for a repository”的示例代码
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/labels
Response
Status: 200
[
{
"id": 208045946,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDY=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/bug",
"name": "bug",
"description": "Something isn't working",
"color": "f29513",
"default": true
},
{
"id": 208045947,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDc=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/enhancement",
"name": "enhancement",
"description": "New feature or request",
"color": "a2eeef",
"default": false
}
]
Create a label
Creates a label for the specified repository with the given name and color. The name and color parameters are required. The color must be a valid hexadecimal color code.
“Create a label”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (write)
- "Pull requests" repository permissions (write)
“Create a label”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
名称, 类型, 说明 |
---|
name string 必须The name of the label. Emoji can be added to label names, using either native emoji or colon-style markup. For example, typing |
color string The hexadecimal color code for the label, without the leading |
description string A short description of the label. Must be 100 characters or fewer. |
“Create a label”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
201 | Created |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
“Create a label”的示例代码
请求示例
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/labels \
-d '{"name":"bug","description":"Something isn'\''t working","color":"f29513"}'
Response
Get a label
Gets a label using the given name.
“Get a label”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (read)
- "Pull requests" repository permissions (read)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。
“Get a label”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
name string 必须 |
“Get a label”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
404 | Resource not found |
“Get a label”的示例代码
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/labels/NAME
Response
Update a label
Updates a label using the given label name.
“Update a label”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (write)
- "Pull requests" repository permissions (write)
“Update a label”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
name string 必须 |
名称, 类型, 说明 |
---|
new_name string The new name of the label. Emoji can be added to label names, using either native emoji or colon-style markup. For example, typing |
color string The hexadecimal color code for the label, without the leading |
description string A short description of the label. Must be 100 characters or fewer. |
“Update a label”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
“Update a label”的示例代码
请求示例
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/labels/NAME \
-d '{"new_name":"bug :bug:","description":"Small bug fix required","color":"b01f26"}'
Response
Delete a label
Deletes a label using the given label name.
“Delete a label”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (write)
- "Pull requests" repository permissions (write)
“Delete a label”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
name string 必须 |
“Delete a label”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
204 | No Content |
“Delete a label”的示例代码
请求示例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/labels/NAME
Response
Status: 204
List labels for issues in a milestone
Lists labels for issues in a milestone.
“List labels for issues in a milestone”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须至少具有以下权限集之一:
- "Issues" repository permissions (read)
- "Pull requests" repository permissions (read)
如果仅请求公共资源,则无需身份验证或上述权限即可使用此终结点。
“List labels for issues in a milestone”的参数
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
milestone_number integer 必须The number that identifies the milestone. |
名称, 类型, 说明 |
---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." 默认: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." 默认: |
“List labels for issues in a milestone”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
200 | OK |
“List labels for issues in a milestone”的示例代码
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/milestones/MILESTONE_NUMBER/labels
Response
Status: 200
[
{
"id": 208045946,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDY=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/bug",
"name": "bug",
"description": "Something isn't working",
"color": "f29513",
"default": true
},
{
"id": 208045947,
"node_id": "MDU6TGFiZWwyMDgwNDU5NDc=",
"url": "https://HOSTNAME/repos/octocat/Hello-World/labels/enhancement",
"name": "enhancement",
"description": "New feature or request",
"color": "a2eeef",
"default": false
}
]