Help us learn about your current experience with the documentation. Take the survey.
标签 API
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
使用标签 API 来创建、管理和删除 Git 标签。此 API 还会返回已签名标签的 X.509 签名信息。
列出项目仓库标签
获取项目中仓库标签的列表,按更新日期和时间降序排列。
如果仓库是公开可访问的,则不需要身份验证(--header "PRIVATE-TOKEN: <your_access_token>")。
GET /projects/:id/repository/tags参数:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 项目的 ID 或 URL 编码的项目路径。 |
order_by |
string | no | 按 name、updated 或 version 排序返回标签。默认为 updated。 |
sort |
string | no | 按 asc 或 desc 顺序返回标签。默认为 desc。 |
search |
string | no | 返回符合搜索条件的标签列表。您可以使用 ^term 和 term$ 来查找以 term 开头和结尾的标签。不支持其他正则表达式。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/repository/tags"示例响应:
[
{
"commit": {
"id": "2695effb5807a22ff3d138d593fd856244e155e7",
"short_id": "2695effb",
"title": "Initial commit",
"created_at": "2017-07-26T11:08:53.000+02:00",
"parent_ids": [
"2a4b78934375d7f53875269ffd4f45fd83a84ebe"
],
"message": "Initial commit",
"author_name": "John Smith",
"author_email": "john@example.com",
"authored_date": "2012-05-28T04:42:42-07:00",
"committer_name": "Jack Smith",
"committer_email": "jack@example.com",
"committed_date": "2012-05-28T04:42:42-07:00"
},
"release": {
"tag_name": "1.0.0",
"description": "Amazing release. Wow"
},
"name": "v1.0.0",
"target": "2695effb5807a22ff3d138d593fd856244e155e7",
"message": null,
"protected": true,
"created_at": "2017-07-26T11:08:53.000+02:00"
}
]获取单个仓库标签
根据名称获取特定的仓库标签。如果仓库是公开可访问的,则无需身份验证即可访问此端点。
GET /projects/:id/repository/tags/:tag_name参数:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 项目的 ID 或 URL 编码的项目路径。 |
tag_name |
string | yes | 标签的名称。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/repository/tags/v1.0.0"示例响应:
{
"name": "v5.0.0",
"message": null,
"target": "60a8ff033665e1207714d6670fcd7b65304ec02f",
"commit": {
"id": "60a8ff033665e1207714d6670fcd7b65304ec02f",
"short_id": "60a8ff03",
"title": "Initial commit",
"created_at": "2017-07-26T11:08:53.000+02:00",
"parent_ids": [
"f61c062ff8bcbdb00e0a1b3317a91aed6ceee06b"
],
"message": "v5.0.0\n",
"author_name": "Arthur Verschaeve",
"author_email": "contact@arthurverschaeve.be",
"authored_date": "2015-02-01T21:56:31.000+01:00",
"committer_name": "Arthur Verschaeve",
"committer_email": "contact@arthurverschaeve.be",
"committed_date": "2015-02-01T21:56:31.000+01:00"
},
"release": null,
"protected": false,
"created_at": "2017-07-26T11:08:53.000+02:00"
}创建新标签
在仓库中创建一个指向指定引用的新标签。
POST /projects/:id/repository/tags参数:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 项目的 ID 或 URL 编码的项目路径。 |
tag_name |
string | yes | 标签的名称。 |
ref |
string | yes | 从提交 SHA、其他标签名称或分支名称创建标签。 |
message |
string | no | 创建一个带注释的标签。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/repository/tags?tag_name=test&ref=main"示例响应:
{
"commit": {
"id": "2695effb5807a22ff3d138d593fd856244e155e7",
"short_id": "2695effb",
"title": "Initial commit",
"created_at": "2017-07-26T11:08:53.000+02:00",
"parent_ids": [
"2a4b78934375d7f53875269ffd4f45fd83a84ebe"
],
"message": "Initial commit",
"author_name": "John Smith",
"author_email": "john@example.com",
"authored_date": "2012-05-28T04:42:42-07:00",
"committer_name": "Jack Smith",
"committer_email": "jack@example.com",
"committed_date": "2012-05-28T04:42:42-07:00"
},
"release": null,
"name": "v1.0.0",
"target": "2695effb5807a22ff3d138d593fd856244e155e7",
"message": null,
"protected": false,
"created_at": null
}创建的标签类型决定了 created_at、target 和 message 的内容:
- 对于带注释的标签:
created_at包含标签创建的时间戳。message包含注释内容。target包含标签对象的 ID。
- 对于轻量级标签:
created_at为 null。message为 null。target包含提交 ID。
错误返回状态码 405 并附带解释性错误消息。
删除标签
删除指定名称的仓库标签。
DELETE /projects/:id/repository/tags/:tag_name参数:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 项目的 ID 或 URL 编码的项目路径。 |
tag_name |
string | yes | 标签的名称。 |
获取标签的 X.509 签名
如果标签已签名,则获取标签的 X.509 签名。未签名的标签返回 404 Not Found 响应。
GET /projects/:id/repository/tags/:tag_name/signature参数:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 项目的 ID 或 URL 编码的项目路径。 |
tag_name |
string | yes | 标签的名称。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/repository/tags/v1.1.1/signature"标签为 X.509 签名的示例响应:
{
"signature_type": "X509",
"verification_status": "unverified",
"x509_certificate": {
"id": 1,
"subject": "CN=gitlab@example.org,OU=Example,O=World",
"subject_key_identifier": "BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC",
"email": "gitlab@example.org",
"serial_number": 278969561018901340486471282831158785578,
"certificate_status": "good",
"x509_issuer": {
"id": 1,
"subject": "CN=PKI,OU=Example,O=World",
"subject_key_identifier": "AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB",
"crl_url": "http://example.com/pki.crl"
}
}
}标签未签名的示例响应:
{
"message": "404 GPG Signature Not Found"
}