{{< details >}}
- Tier: 基础版,专业版,旗舰版
- Offering: JihuLab.com,私有化部署
{{< /details >}}
使用此 API 与项目主题互动。有关更多信息,请参阅项目主题。
列出主题
返回极狐GitLab 实例中按相关项目数量排序的项目主题列表。
GET /topics
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
page |
integer | No | 要检索的页面。默认为 1 。 |
per_page |
integer | No | 每页返回的记录数。默认为 20 。 |
search |
string | No | 根据 name 搜索主题。 |
without_projects |
boolean | No | 将结果限制为没有分配项目的主题。 |
示例请求:
curl "https://gitlab.example.com/api/v4/topics?search=git"
示例响应:
[
{
"id": 1,
"name": "gitlab",
"title": "GitLab",
"description": "GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more.",
"total_projects_count": 1000,
"organization_id": 1,
"avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon"
},
{
"id": 3,
"name": "git",
"title": "Git",
"description": "Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.",
"total_projects_count": 900,
"organization_id": 1,
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
},
{
"id": 2,
"name": "git-lfs",
"title": "Git LFS",
"description": null,
"total_projects_count": 300,
"organization_id": 1,
"avatar_url": null
}
]
获取主题
通过 ID 获取项目主题。
GET /topics/:id
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer | Yes | 项目主题的 ID |
示例请求:
curl "https://gitlab.example.com/api/v4/topics/1"
示例响应:
{
"id": 1,
"name": "gitlab",
"title": "GitLab",
"description": "GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more.",
"total_projects_count": 1000,
"organization_id": 1,
"avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon"
}
列出分配给主题的项目
使用 Projects API 列出分配给特定主题的所有项目。
GET /projects?topic=<topic_name>
创建项目主题
创建新的项目主题。仅限管理员使用。
POST /topics
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
name |
string | Yes | Slug (名称) |
title |
string | Yes | 标题 |
avatar |
file | No | 头像 |
description |
string | No | 描述 |
organization_id |
integer | No | 主题的组织 ID。WARNING: 此属性是实验性的,未来可能会发生变化。有关组织的更多信息,请参阅 Organizations API |
示例请求:
curl --request POST \
--data "name=topic1&title=Topic 1" \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics"
示例响应:
{
"id": 1,
"name": "topic1",
"title": "Topic 1",
"description": null,
"total_projects_count": 0,
"organization_id": 1,
"avatar_url": null
}
更新项目主题
更新项目主题。仅限管理员使用。
PUT /topics/:id
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer | Yes | 项目主题的 ID |
avatar |
file | No | 头像 |
description |
string | No | 描述 |
name |
string | No | Slug (名称) |
title |
string | No | 标题 |
示例请求:
curl --request PUT \
--data "name=topic1" \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics/1"
示例响应:
{
"id": 1,
"name": "topic1",
"title": "Topic 1",
"description": null,
"total_projects_count": 0,
"organization_id": 1,
"avatar_url": null
}
上传主题头像
要从文件系统上传头像文件,请使用 --form
参数。此参数使 cURL 使用 Content-Type: multipart/form-data
标头发布数据。file=
参数必须指向文件系统上的文件,并以 @
为前缀。例如:
curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics/1" \
--form "avatar=@/tmp/example.png"
删除主题头像
要删除主题头像,请为 avatar
属性使用空值。
示例请求:
curl --request PUT \
--data "avatar=" \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics/1"
删除项目主题
您必须是管理员才能删除项目主题。删除项目主题时,还会删除项目的主题分配。
DELETE /topics/:id
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer | Yes | 项目主题的 ID |
示例请求:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics/1"
合并主题
{{< history >}}
- 在极狐GitLab 15.4 中 Introduced。
{{< /history >}}
您必须是管理员才能将源主题合并到目标主题中。合并主题时,您将删除源主题并将所有分配的项目移动到目标主题。
POST /topics/merge
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
source_topic_id |
integer | Yes | 源项目主题的 ID |
target_topic_id |
integer | Yes | 目标项目主题的 ID |
{{< alert type=”note” >}}
source_topic_id
和 target_topic_id
必须属于同一组织。
{{< /alert >}}
示例请求:
curl --request POST \
--data "source_topic_id=2&target_topic_id=1" \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/topics/merge"
示例响应:
{
"id": 1,
"name": "topic1",
"title": "Topic 1",
"description": null,
"total_projects_count": 0,
"organization_id": 1,
"avatar_url": null
}