GitLab API的以下REST URL爲我提供了項目的存儲庫樹。如何通過GitLab REST API獲取文件的原始內容?
獲取回購樹(工程)
https://gitlab.gspt.net/api/v3/projects/2931/repository/tree?private_token=XXXX
輸出:
[
{
"id": "a49d11794ed56db7f935abfd61002aef67159d10",
"name": "src",
"type": "tree",
"path": "src",
"mode": "040000"
},
{
"id": "0fbd98527d4b36e3d22c164293d8fd8eee4d18cd",
"name": ".gitignore",
"type": "blob",
"path": ".gitignore",
"mode": "100644"
},
{
"id": "0ef0da472176f2e6a24843ac9d4bb738c8310d23",
"name": "pom.xml",
"type": "blob",
"path": "pom.xml",
"mode": "100644"
}
]
但我不能夠得到一個文件的原始內容,pom.xml的是精確。
獲取文件的原始內容(不工作 - 給404)
https://gitlab.gspt.net/api/v3/projects/2931/repository/files/pom%2Exml/raw?private_token=xxxx&ref_name=master
輸出:
{
"error": "404 Not Found"
}
按照這裏的文檔(https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository)我指定正確的休息網址。但唯一不同的是在其他api端點中使用V4而不是V3。我四處搜索,但無法找到v3 api的端點。
非常感謝馮,我使用這個URL獲得了文件的內容:'https://gitlab.gspt.net/api/v3/projects/2931/repository/files?file_path = pom.xml&ref = master' 。但是,文件的內容是編碼的。如何獲取原始內容? – user2325154
@ user2325154通過使用'/ projects /:id/repository/raw_blobs /:sha'語法,我在答案中提到:請參閱https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9637/diffs# 4d37e90ff02b5014b4a2fda7e01b5c67fb686c11_96_96 – VonC
不確定在':sha'中指定什麼。 ':sha'是文件的commit-id嗎?我查看了您提供的鏈接,但沒有提及如何獲取文件的原始內容。我從上述URL獲得的內容是'base64'編碼的。我總是可以解碼並獲取文件的實際原始內容。但是有沒有辦法直接獲取文件的原始內容? – user2325154