{"meta":{"title":"存储库标记的 REST API 端点","intro":"使用 REST API 管理存储库的标记。","product":"REST API","breadcrumbs":[{"href":"/zh/enterprise-server@3.17/rest","title":"REST API"},{"href":"/zh/enterprise-server@3.17/rest/repos","title":"存储库"},{"href":"/zh/enterprise-server@3.17/rest/repos/tags","title":"标签"}],"documentType":"article"},"body":"# 存储库标记的 REST API 端点\n\n使用 REST API 管理存储库的标记。\n\n> [!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2022-11-28`. Curl examples below omit these standard headers for brevity.\n\n## Closing down - List tag protection states for a repository\n\n```\nGET /repos/{owner}/{repo}/tags/protection\n```\n\nWarning\n\nClosing down notice: This operation is closing down and will be removed after August 30, 2024. Use the \"Repository Rulesets\" endpoint instead.\n\nThis returns the tag protection states of a repository.\nThis information is only available to repository administrators.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **403** - Forbidden\n\n- **404** - Resource not found\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/tags/protection\n```\n\n**Response schema (Status: 200):**\n\nArray of `Tag protection`:\n  * `id`: integer\n  * `created_at`: string\n  * `updated_at`: string\n  * `enabled`: boolean\n  * `pattern`: required, string\n\n## Closing down - Create a tag protection state for a repository\n\n```\nPOST /repos/{owner}/{repo}/tags/protection\n```\n\nWarning\n\nClosing down notice: This operation is closing down and will be removed after August 30, 2024. Use the \"Repository Rulesets\" endpoint instead.\n\nThis creates a tag protection state for a repository.\nThis endpoint is only available to repository administrators.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n#### Body parameters\n\n- **`pattern`** (string) (required)\n  An optional glob pattern to match against when enforcing tag protection.\n\n### HTTP response status codes\n\n- **201** - Created\n\n- **403** - Forbidden\n\n- **404** - Resource not found\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/tags/protection \\\n  -d '{\n  \"pattern\": \"v1.*\"\n}'\n```\n\n**Response schema (Status: 201):**\n\n* `id`: integer\n* `created_at`: string\n* `updated_at`: string\n* `enabled`: boolean\n* `pattern`: required, string\n\n## Closing down - Delete a tag protection state for a repository\n\n```\nDELETE /repos/{owner}/{repo}/tags/protection/{tag_protection_id}\n```\n\nWarning\n\nClosing down notice: This operation is closing down and will be removed after August 30, 2024. Use the \"Repository Rulesets\" endpoint instead.\n\nThis deletes a tag protection state for a repository.\nThis endpoint is only available to repository administrators.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`tag_protection_id`** (integer) (required)\n  The unique identifier of the tag protection.\n\n### HTTP response status codes\n\n- **204** - No Content\n\n- **403** - Forbidden\n\n- **404** - Resource not found\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/tags/protection/TAG_PROTECTION_ID\n```\n\n**Response schema (Status: 204):**"}