使用以下命令,我可以获取 GitHub 存储库上的文件的
download_url
,但它不包括文件夹内的文件:
curl -H "Authorization: token ghp_..." -H "Accept: application/vnd.github.v3.raw" -L "https://api.github.com/repos/<USER>/<REPO>/contents"
在四处搜索时,我发现了这个答案,以下命令递归地列出了所有文件,但它不包括
download_url
:
curl -H "Authorization: token ghp_..." -H "Accept: application/vnd.github.v3.raw" -L "https://api.github.com/repos/<USER>/<REPO>/git/trees/main?recursive=1"
我如何获得存储库中
download_url
的ALL文件?
使用从
path
端点返回的对象的“/repos/{owner}/{repo}/git/trees/{tree_sha}
”成员构造 download_url。
模板看起来是
https://raw.githubusercontent.com/{owner}/{repo}/{branch/commit-sha/tree-sha}/{path}