Gitlab API 常用功能整理

Phanix
·
·
IPFS
·

Gitlab 提供了一些api ,回传资料皆是以JSON 格式表示,不管是要写程式来协助做管理,或者是要从command line 用curl 来做一些事情都还蛮方便的,毕竟web 介面有时候就是比较慢一点…

Group 相关

使用的时候需要在header 给予token作为验证, token 可以在个人帐号的setting 底下找到。

 $ curl --header "PRIVATE-TOKEN:YOUR_TOKEN" "http://YOUR.GITLAB.SERVER.DOMAIN/api/v4/groups" #列出所有group
$ curl --header "PRIVATE-TOKEN:YOUR_TOKEN" "http://YOUR.GITLAB.SERVER.DOMAIN/api/v4/groups?search=system" #以keyword = "system" 做搜寻[{"id":58,"name":"frsystem","path":"frsystem","description":"for face recognition system","visibility":"private","lfs_enabled":true,"avatar_url":null,"web_url":"http://YOUR.GITLAB.SERVER.DOMAIN/groups/frsystem","request_access_enabled":true,"full_name":"frsystem","full_path":"frsystem","parent_id":null},{"id":189,"name":"system","path":"system","description":"","visibility":"private","lfs_enabled":true,"avatar_url":null,"web_url":"http://YOUR.GITLAB.SERVER.DOMAIN/groups/system","request_access_enabled":false,"full_name":"system","full_path":"system","parent_id":null},{"id":129,"name":"vipfr_system","path":"vipfr_system","description":"vip face recognition system which use QT as gui","visibility":"private","lfs_enabled":true,"avatar_url":null,"web_url":"http://YOUR.GITLAB.SERVER.DOMAIN/groups/vipfr_system","request_access_enabled":false,"full_name":"vipfr_sys tem","full_path":"vipfr_system","parent_id":null}]
$ curl --header "PRIVATE-TOKEN:YOUR_TOKEN" "http://YOUR.GITLAB.SERVER.DOMAIN/api/v4/groups/190/subgroups" #找编号190 这个group 底下的subgroups
[{"id":191,"name":"service","path":"service","description":"","visibility":"private","lfs_enabled":true,"avatar_url":null,"web_url":"http://YOUR.GITLAB.SERVER.DOMAIN/groups/system/alg/service","request_access_enabled":false,"full_name":"system / alg / service","full_path":"system/alg/service","parent_id":190}]
$ curl --header "PRIVATE-TOKEN:YOUR_TOKEN" "http://YOUR.GITLAB.SERVER.DOMAIN/api/v4/groups/191" #查询group 详细资料$ curl --header "PRIVATE-TOKEN:YOUR_TOKEN" -X POST "http://YOUR.GITLAB.SERVER.DOMAIN/api/v4/groups?name=FV_android&path=FV_android&visibility=private"
$ curl --header "PRIVATE-TOKEN:YOUR_TOKEN" -X POST "http://YOUR.GITLAB.SERVER.DOMAIN/api/v4/groups?name=system&path=system&parent_id=203&visibility=private" #用POST 来做新增,并给定parent_id 来指定parent group

Project 相关

$ curl --header "PRIVATE-TOKEN:YOUR_TOKEN" -X POST "http://YOUR.GITLAB.SERVER.DOMAIN/api/v4/projects?name=face-swap&visibility=private&namespace_id=191" #用POST 来做新增,并给定namespace_id,所以建立出来的project 将挂在191 这编号的group 底下

Original link: Phanix's Blog

CC BY-NC-ND 2.0 授权

喜欢我的作品吗?别忘了给予支持与赞赏,让我知道在创作的路上有你陪伴,一起延续这份热忱!