Gitlab API 常用功能整理
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_system","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