Labels API

Labels API

注意: 已添加到GitLab 12.7 中的响应 JSON.

获取给定项目的所有标签.

默认情况下,此请求一次返回 20 个结果,因为 API 结果 .

  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/labels?with_counts=true"

响应示例:

  1. [ { "id" : 1, "name" : "bug", "color" : "#d9534f", "text_color" : "#FFFFFF", "description": "Bug reported by user", "description_html": "Bug reported by user", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 1, "subscribed": false, "priority": 10, "is_project_label": true }, { "id" : 4, "color" : "#d9534f", "text_color" : "#FFFFFF", "name" : "confirmed", "description": "Confirmed issue", "description_html": "Confirmed issue", "open_issues_count": 2, "closed_issues_count": 5, "open_merge_requests_count": 0, "subscribed": false, "priority": null, "is_project_label": true }, { "id" : 7, "name" : "critical", "color" : "#d9534f", "text_color" : "#FFFFFF", "description": "Critical issue. Need fix ASAP", "description_html": "Critical issue. Need fix ASAP", "open_issues_count": 1, "closed_issues_count": 3, "open_merge_requests_count": 1, "subscribed": false, "priority": null, "is_project_label": true }, { "id" : 8, "name" : "documentation", "color" : "#f0ad4e", "text_color" : "#FFFFFF", "description": "Issue about documentation", "description_html": "Issue about documentation", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 2, "subscribed": false, "priority": null, "is_project_label": false }, { "id" : 9, "color" : "#5cb85c", "text_color" : "#FFFFFF", "name" : "enhancement", "description": "Enhancement proposal", "description_html": "Enhancement proposal", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 1, "subscribed": true, "priority": null, "is_project_label": true } ]

Get a single project label

获取给定项目的单个标签.

  1. GET /projects/:id/labels/:label_id
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
label_id 整数或字符串 yes 项目标签的 ID 或标题.
include_ancestor_groups boolean no 包括祖先组. 默认为true .
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/labels/bug"

响应示例:

  1. { "id" : 1, "name" : "bug", "color" : "#d9534f", "text_color" : "#FFFFFF", "description": "Bug reported by user", "description_html": "Bug reported by user", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 1, "subscribed": false, "priority": 10, "is_project_label": true }
  1. POST /projects/:id/labels

响应示例:

    Delete a label

    删除具有给定名称的标签.

    1. DELETE /projects/:id/labels/:label_id
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的项目的 ID 或
    label_id 整数或字符串 yes 群组标签的 ID 或标题.
    1. curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/labels/bug"

    注意:参数中带有name的较旧的端点DELETE /projects/:id/labels仍然可用,但已弃用.

    用新名称或新颜色更新现有标签. 至少需要一个参数来更新标签.

    1. PUT /projects/:id/labels/:label_id
    1. curl --request PUT --data "new_name=docs&color=#8E44AD&description=Documentation" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/labels/documentation"

    响应示例:

    注意:参数中带有namelabel_id的较早的端点PUT /projects/:id/labels仍然可用,但已弃用.

    Promote a project label to a group label

    将项目标签提升为组标签.

    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
    label_id 整数或字符串 yes 群组标签的 ID 或标题.
    1. curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/labels/documentation/promote"

    响应示例:

    1. { "id" : 8, "name" : "documentation", "color" : "#8E44AD", "description": "Documentation", "description_html": "Documentation", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 2, "subscribed": false }

    注意:在参数中带有name的较早的端点PUT /projects/:id/labels/promote仍然可用,但已弃用.

    将经过身份验证的用户订阅标签以接收通知. 如果用户已经订阅了标签,则返回状态码304 .

    1. POST /projects/:id/labels/:label_id/subscribe
    1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/labels/1/subscribe"

    响应示例:

    1. { "id" : 1, "name" : "bug", "color" : "#d9534f", "text_color" : "#FFFFFF", "description": "Bug reported by user", "description_html": "Bug reported by user", "open_issues_count": 1, "closed_issues_count": 0, "open_merge_requests_count": 1, "subscribed": true, "priority": null, "is_project_label": true }

    Unsubscribe from a label

    Unsubscribes the authenticated user from a label to not receive notifications from it. If the user is not subscribed to the label, the status code 304 is returned.

    1. POST /projects/:id/labels/:label_id/unsubscribe
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的项目的 ID 或
    label_id 整数或字符串 yes 项目标签的 ID 或标题