Git API - 下载指定仓库代码
1.通过python 下载仓库代码
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/archive?sha=<commit_sha>"
python代码实现:
def download_url():
url = "https://gitlab.com/api/v4/projects/27484667/repository/archive.zip"
token = "JRJH-gXqmUir8PT"
target_path = 'xlrd-0.9.5.zip'
chunk_size = 128
params = {"private_token": token,
"sha":"286e0e2e389a126d4f08db7bd7cfd08f5c40"}
r = requests.get(url,params=params,stream=True)
with open(target_path, 'wb') as fd:
# fd.write((r.raw.read()))
for chunk in r.iter_content(chunk_size=chunk_size):
fd.write(chunk)
if __name__=="__main__":
download_url()