最近在研究通過API獲取gitlab倉庫代碼提交記錄:官方API
發現API中是使用The ID or URL-encoded path of the project 來區分項目的。
爲了方便與準確當然是使用ID最好了,對於自己是倉庫管理員的項目,projectID是比較方面找到的,路徑如下
Settings -> General project settings -> Expand -> Project ID
但是如果自己僅能訪問,無法進入設置界面的倉庫怎麼獲取Project ID呢?
方法有二:
- 方法一:直接get請求
查詢指定項目:https://gitlab.com/api/v4/projects?search=projectname
查詢完整列表:https://gitlab.com/api/v4/projects
但是這樣的話,只會顯示public的項目,如果想要查詢私有倉庫,需要攜帶參數private token
個人賬號-Profile Settings-account 生成api private token
api/v3 版本
https://gitlab.example.com/api/v3/projects?simple=true&private-token= <your_access_token>
api/v4 版本
curl --header “PRIVATE-TOKEN: <your_access_token>” “https://gitlab.example.com/api/v4/projects?simple=true”
方法二(最快捷):
進入目標項目頁面-顯示網頁源代碼,直接搜索:project_id。