2017-07-12 122 views

回答

5

如果只您的私人令牌可用,你只能使用API​​:

項目

使用以下內容要求的項目:

curl "https://<host/api/v4/projects?private_token=<your private token>"

這將返回你前20條。爲了獲得更多的你可以用這個參數可以20100條目之間請加paramater per_page

curl "https://<host/api/v4/projects?private_token=<your private token>&per_page=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 

兩個interessting部分是X-TotalX-Total-Pages,首先是繳費條目的數量和第二總頁數的計數。

我建議使用python或其他類型的腳本來處理請求並在最後連接結果。

如果要細化搜索諮詢此Wiki網頁: https://docs.gitlab.com/ce/api/projects.html#projects-api

適合人羣只需更換projects用捲髮groupshttps://docs.gitlab.com/ce/api/groups.html#list-groups


UPDATE: 這裏是Gitlab API客戶機/包裝的正式名單:https://about.gitlab.com/applications/#api-clients
我強烈建議使用其中之一。

+0

非常感謝@secustor。 – Bond

+0

curl是否有任何理由不返回Gitlab中的所有項目/頁面?我是管理員,但使用我的令牌似乎並未檢索所有項目。但是,如果我查看UI,我可以看到所有的項目。 – Bond

+0

如果令牌是管理員的私人令牌,則應該獲得所有項目或組。您是否按照我的回答中所述循環瀏覽頁面? – secustor

相關問題