我想进行一些数据研究,并想使用 Github GraphQL API 从搜索结果中下载存储库内容。
我已经找到的是如何进行简单的搜索查询,但问题是: 如何从搜索结果中下载存储库内容?
这是我当前返回存储库名称和描述的代码 (try to run here):
{
search(query: "example", type: REPOSITORY, first: 20) {
repositoryCount
edges {
node {
... on Repository {
name
descriptionHTML
}
}
}
}
}
最佳答案
您可以使用以下命令获取存储库默认分支上最新提交的 tarball/zipball url:
{
repository(owner: "google", name: "gson") {
defaultBranchRef {
target {
... on Commit {
tarballUrl
zipballUrl
}
}
}
}
}
使用搜索查询,您可以使用以下内容:
{
search(query: "example", type: REPOSITORY, first: 20) {
repositoryCount
edges {
node {
... on Repository {
defaultBranchRef {
target {
... on Commit {
zipballUrl
}
}
}
}
}
}
}
}
使用 curl 下载该搜索的所有 zip 的脚本, jq & xargs :
curl -s -H "Authorization: bearer YOUR_TOKEN" -d '
{
"query": "query { search(query: \"example\", type: REPOSITORY, first: 20) { repositoryCount edges { node { ... on Repository { defaultBranchRef { target { ... on Commit { zipballUrl } }}}}}}}"
}
' https://api.github.com/graphql | jq -r '.data.search.edges[].node.defaultBranchRef.target.zipballUrl' | xargs -I{} curl -O {}
关于git - 如何通过 GraphQL API 搜索下载 Github 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47458143/