gitlab如何查询项目ID

最近在研究通过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。
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章