如何通过 GraphQL API 搜索下载 Github 存储库? [英] How to download Github repositories via GraphQL API search?
问题描述
我想进行一些数据研究,并想使用 Github GraphQL API 从搜索结果中下载存储库内容.
I want to make some data researches and want to download repositories content from the search results with Github GraphQL API.
我已经找到了如何进行简单的搜索查询,但问题是:如何从搜索结果中下载存储库内容?
What I already found is how to make simple search query, but the question is: How to download repositories content from the search results?
这是我当前返回存储库名称和描述的代码(尝试在此处运行):
Here is my current code that returns repositories name and description (try to run here):
{
search(query: "example", type: REPOSITORY, first: 20) {
repositoryCount
edges {
node {
... on Repository {
name
descriptionHTML
}
}
}
}
}
推荐答案
您可以使用以下命令获取仓库默认分支上最新提交的 tarball/zipball url:
You can get the tarball/zipball url for the latest commit on the default branch of a repo with the following :
{
repository(owner: "google", name: "gson") {
defaultBranchRef {
target {
... on Commit {
tarballUrl
zipballUrl
}
}
}
}
}
使用搜索查询,您可以使用以下内容:
Using a search query, you can use the following :
{
search(query: "example", type: REPOSITORY, first: 20) {
repositoryCount
edges {
node {
... on Repository {
defaultBranchRef {
target {
... on Commit {
zipballUrl
}
}
}
}
}
}
}
}
使用 curl<下载该搜索的所有 zip 的脚本/a>,jq &xargs :
A script that download all zip of that search using curl,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 {}
这篇关于如何通过 GraphQL API 搜索下载 Github 存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!