使用CURL列出github存储库树(github API)



使用github API,您可以使用(使用CURL完成的示例(:获得存储库树

curl -H "Accept: application/vnd.github.v3+json" 
https://api.github.com/repos/{owner}/{repo}/git/trees/{tree_sha}

假设我有一个由所有者NewCo称为dev的回购,并且我想列出名为XXXX的回购树,我会:

curl -H "Accept: application/vnd.github.v3+json" 
https://api.github.com/repos/NewCo/dev/git/trees/{tree_sha}

如何查找树XXXX的{tree_sha}值?知道在哪里可以找到这个值吗?

您可以使用来自提交端点的提交sha:/repos/{owner}/{repo}/commits。例如:

#!/usr/bin/env bash
set -e
owner=zacanger
repo=fetchyeah
sha=$(curl -s -H "Accept: application/vnd.github.v3+json" 
https://api.github.com/repos/$owner/$repo/commits?per_page=1 
| jq -r '.[0].sha')
curl -H "Accept: application/vnd.github.v3+json" 
https://api.github.com/repos/$owner/$repo/git/trees/$sha

您还可以使用pull请求API或任何其他返回提交信息的端点(也就是说,除了用户和组织API之外的大多数端点(。

最新更新