gitlab如何查询项目ID

最近在研究通过API获取gitlab仓库代码提交记录:官方API
gitlab如何查询项目ID_第1张图片
发现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
gitlab如何查询项目ID_第2张图片
api/v3 版本
https://gitlab.example.com/api/v3/projects?simple=true&private-token=

api/v4 版本
curl --header “PRIVATE-TOKEN: ” “https://gitlab.example.com/api/v4/projects?simple=true”

方法二(最快捷):
进入目标项目页面-显示网页源代码,直接搜索:project_id。
在这里插入图片描述

你可能感兴趣的:(测试,gitlab,测试)