sec*_*tor 27
如果只有您的私人令牌可用,则只能使用API:
项目
使用以下来请求项目:
curl "https://<host/api/v4/projects?private_token=<your private token>"
这将返回前20个条目.要获得更多,您可以添加参数per_page
curl "https://<host/api/v4/projects?private_token=<your private token>&per_page=100"
使用此参数,您可以在20和100条目之间请求.https://docs.gitlab.com/ce/api/README.html#pagination
如果您现在想要所有项目,则必须遍历页面,以获取另一个页面添加参数page.
curl "https://<host/api/v4/projects?private_token=<your private token>&per_page=100&page=<page_number>"
现在您可能想知道有多少页面.为此,添加curl参数--head.这不会返回有效负载,而是返回标头.
结果将如下所示:
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 13 Jul 2017 17:43:24 GMT
Content-Type: application/json
Content-Length: 29428
Cache-Control: no-cache
Link: <request link>
Vary: Origin
X-Frame-Options: SAMEORIGIN
X-Next-Page: 2
X-Page: 1
X-Per-Page: 20
X-Prev-Page:
X-Request-Id: 80ecc167-4f3f-4c99-b09d-261e240e7fe9
X-Runtime: 4.117558
X-Total: 312257
X-Total-Pages: 15613
Strict-Transport-Security: max-age=31536000
Run Code Online (Sandbox Code Playgroud)
两个有趣的部分是X-Total和X-Total-Pages,第一个是可用条目的数量,第二个是总页数.
我建议使用python或其他类型的脚本来处理请求并在结尾处连接结果.
如果您想要优化搜索,请参阅此Wiki页面:https: //docs.gitlab.com/ce/api/projects.html#projects-api
组
对于组只需更换projects用groups的卷发.
https://docs.gitlab.com/ce/api/groups.html#list-groups
更新:
以下是Gitlab API客户端/包装器的官方列表:https ://about.gitlab.com/applications/#api-clients
我强烈建议使用其中之一.
小智 7
在 Gitlab API V4 的 bash 中:
#!/bin/bash
GL_DOMAIN=""
GL_TOKEN=""
echo "" > gitlab_projects_urls.txt
for ((i=1; ; i+=1)); do
contents=$(curl "$GL_DOMAIN/api/v4/projects?private_token=$GL_TOKEN&per_page=100&page=$i")
if jq -e '. | length == 0' >/dev/null; then
break
fi <<< "$contents"
echo "$contents" | jq -r '.[].ssh_url_to_repo' >> gitlab_projects_urls.txt
done
Run Code Online (Sandbox Code Playgroud)