使用 GitLab api 列出 GitLab 存储库名称

Listing GitLab Repositories name using GitLab api

我只想使用 GitLab API 列出 GitLab 存储库名称。

我试过命令curl "https://gitlab.com/api/v4/projects?private_token=*************"

它列出了所有合并请求、问题以及存储库名称。

如何只列出存储库名称?

没有办法仅通过 API 将响应限制为单个字段,但是有 simple 选项 return 最小字段集:

https://docs.gitlab.com/ee/api/projects.html#list-all-projects

curl "https://gitlab.com/api/v4/projects?simple=true&private_token=*************" 会 return 类似于:

[
  {
    "id": 4,
    "description": null,
    "default_branch": "master",
    "ssh_url_to_repo": "git@example.com:diaspora/diaspora-client.git",
    "http_url_to_repo": "http://example.com/diaspora/diaspora-client.git",
    "web_url": "http://example.com/diaspora/diaspora-client",
    "readme_url": "http://example.com/diaspora/diaspora-client/blob/master/README.md",
    "tag_list": [ //deprecated, use `topics` instead
      "example",
      "disapora client"
    ],
    "topics": [
      "example",
      "disapora client"
    ],
    "name": "Diaspora Client",
    "name_with_namespace": "Diaspora / Diaspora Client",
    "path": "diaspora-client",
    "path_with_namespace": "diaspora/diaspora-client",
    "created_at": "2013-09-30T13:46:02Z",
    "last_activity_at": "2013-09-30T13:46:02Z",
    "forks_count": 0,
    "avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png",
    "star_count": 0
  },
  {
    "id": 6,
    "description": null,
    "default_branch": "master",
...

正如 Igor 提到的,Gitlab API 不允许您将响应限制为单个字段。

我建议将原始 API 调用与 jq 命令结合使用。 这将启用对返回的 json

的解析
curl "https://gitlab.com/api/v4/projects?private_token=*************" | jq '.[].name'