如何通过GraphQL API搜索下载Github存储库?
我想进行一些数据研究,并希望使用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网址:
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
}
}
}
}
}
}
}
}
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 {}