Skip to main content
We publish frequent updates to our documentation, and translation of this page may still be in progress. For the most current information, please visit the English documentation.

We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the new Branches, Collaborators, Commits, Deploy Keys, Deployments, GitHub Pages, Releases, Metrics, Webhooks REST API pages.

存储库标记

使用 REST API 管理存储库的标记。

List tag protection states for a repository

Works with GitHub Apps

This returns the tag protection states of a repository.

This information is only available to repository administrators.

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

HTTP response status codes

Status code说明
200

OK

403

Forbidden

404

Resource not found

Code samples

get/repos/{owner}/{repo}/tags/protection
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/tags/protection

Response

Status: 200
[ { "id": 2, "pattern": "v1.*" } ]

Create a tag protection state for a repository

Works with GitHub Apps

This creates a tag protection state for a repository. This endpoint is only available to repository administrators.

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

Body parameters
名称, Type, 说明
patternstringRequired

An optional glob pattern to match against when enforcing tag protection.

HTTP response status codes

Status code说明
201

Created

403

Forbidden

404

Resource not found

Code samples

post/repos/{owner}/{repo}/tags/protection
curl \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/tags/protection \ -d '{"pattern":"v1.*"}'

Response

Status: 201
{ "enabled": true }

Delete a tag protection state for a repository

Works with GitHub Apps

This deletes a tag protection state for a repository. This endpoint is only available to repository administrators.

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

tag_protection_idintegerRequired

The unique identifier of the tag protection.

HTTP response status codes

Status code说明
204

No Content

403

Forbidden

404

Resource not found

Code samples

delete/repos/{owner}/{repo}/tags/protection/{tag_protection_id}
curl \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/tags/protection/TAG_PROTECTION_ID

Response

Status: 204