2017-06-28 88 views
1

我們在我們的組織中有一個inhouse gitlab託管的回購,我是開發人員,他沒有管理員訪問權限。通過休息API獲取404內部gitlab回購獲得項目的所有分支

但是,我是gitlab中此存儲庫的創建者(https://gitlab.gspt.net/payments/dss),我試圖做的是通過其餘api獲取此回購庫中的所有分支。

在網上做了一些研究並仔細閱讀本文檔後(https://docs.gitlab.com/ce/api/branches.html#protect-repository-branch),我發現我可以使用這個命令獲得所有的repo分支。

GET /projects/:id/repository/branches 

curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/5/repository/branches 

這裏需要私人-TOKEN在頭與我的私人原因,我已經做了更換,現在我想訪問我的gitlab點播服務回購在郵遞員使用以下命令,我得到404

https://gitlab.gspt.net/api/v4/projects/payments/dss/repository/branches 

兩個問題在這裏:

  1. 不知道如果我休息的網址是否正確。我找不到我的項目的id。我掃描了整個gitlab用戶界面,無法找到任何地方的id的痕跡。因此在http url中使用NAMESPACE/PROJECT_NAME,我碰巧在文檔中找到了某處。不知道這是否也是正確的。
  2. 不知道我的內部吉拉布管理員是否已完全禁用http rest api功能。從來沒有安裝和管理一個git repo,所以在這裏也不知道。

對此有何指導?

回答

1

拿到項目ID可以使用projects APIsearch參數

以下bash腳本搜索您的回購名獲得匹配的項目名稱,項目編號,並進行電話的方式獲得項目的分支。它使用jq JSON解析器來解析JSON結果:

#!/bin/bash 

gitlab_host="https://gitlab.gspt.net" 
private_token="9koXpg98eAheJpvBs5tK" 
project_name="dss" 

project_id=$(curl -s "$gitlab_host/api/v3/projects?search=$project_name&private_token=$private_token" | jq '.[0].id') 

if [ "$project_id" == "null" ]; then 
    echo "error could not find project id for project name $project_name" 
    exit 1 
fi 

curl -s "$gitlab_host/api/v3/projects/$project_id/repository/branches?private_token=$private_token" | jq '.[]' 
+0

我試過了你的shell腳本,我得到這個錯誤。 './gitlab-id-finder.sh:第7行:jq:command not found'。我需要安裝任何東西嗎?只是一個FYI,我正在使用Windows 7 – user2325154

+0

是的,它使用[jq](https://stedolan.github.io/jq/)來解析json結果,有一個Windows版本可用 –

+0

通過郵遞員得到它的工作。這有助於很多:)謝謝 – user2325154

相關問題