[英]How to download Github repositories via GraphQL API search?
我想進行一些數據研究,並想使用 Github GraphQL API 從搜索結果中下載存儲庫內容。
我已經找到了如何進行簡單的搜索查詢,但問題是:如何從搜索結果中下載存儲庫內容?
這是我當前返回存儲庫名稱和描述的代碼(嘗試在此處運行):
{
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 、 jq和xargs下載該搜索的所有 zip 的腳本:
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 {}
@tharinduwijewardane
JFYI,您可以通過此查詢下載特定分支的 zip
repository(owner: "owner", name: "repo name") {
object(expression: "branch") {
... on Commit {
zipballUrl
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.