Namespaces API

原文:https://docs.gitlab.com/ee/api/namespaces.html

Namespaces API

用户名和组名属于称为命名空间的特殊类别.

对于用户和组支持的 API 调用,请分别参阅用户文档.

使用分页 .

List namespaces

获取已认证用户的名称空间列表. 如果用户是管理员,则会显示 GitLab 实例中所有名称空间的列表.

  1. GET /namespaces

请求示例:

  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/namespaces"

响应示例:

  1. [ { "id": 1, "name": "user1", "path": "user1", "kind": "user", "full_path": "user1" }, { "id": 2, "name": "group1", "path": "group1", "kind": "group", "full_path": "group1", "parent_id": null, "members_count_with_descendants": 2 }, { "id": 3, "name": "bar", "path": "bar", "kind": "group", "full_path": "foo/bar", "parent_id": 9, "members_count_with_descendants": 5 } ]

GitLab.com Bronze 或更高版本上的用户可能还会看到与名称空间关联的plan参数:

  1. [ { "id": 1, "name": "user1", "plan": "bronze", ... } ]

注意:仅向组维护者/所有者提供了members_count_with_descendantsplan .

Search for namespace

获取与名称或路径中的字符串匹配的所有名称空间.

  1. GET /namespaces?search=foobar
Attribute Type Required Description
search string no 返回基于搜索条件授权用户查看的名称空间列表

请求示例:

  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/namespaces?search=twitter"

响应示例:

  1. [ { "id": 4, "name": "twitter", "path": "twitter", "kind": "group", "full_path": "twitter", "parent_id": null, "members_count_with_descendants": 2 } ]

Get namespace by ID

通过 ID 获取名称空间.

  1. GET /namespaces/:id
Attribute Type Required Description
id integer/string yes 名称空间的 ID 或URL 编码的路径

请求示例:

  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/namespaces/2"

响应示例:

  1. { "id": 2, "name": "group1", "path": "group1", "kind": "group", "full_path": "group1", "parent_id": null, "members_count_with_descendants": 2 }

请求示例:

  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/namespaces/group1"

响应示例:

  1. { "id": 2, "name": "group1", "path": "group1", "kind": "group", "full_path": "group1", "parent_id": null, "members_count_with_descendants": 2 }