如何通过GraphQL API搜索下载Github存储库?

sem*_*ser 4 git api github github-api graphql

我想进行一些数据研究,并希望使用Github GraphQL API从搜索结果中下载存储库内容.

我已经找到的是如何进行简单的搜索查询,但问题是: 如何从搜索结果中下载存储库内容?

这是我当前的代码,它返回存储库名称和描述(尝试在此处运行):

{
  search(query: "example", type: REPOSITORY, first: 20) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          name
          descriptionHTML
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Ber*_*tel 10

您可以使用以下内容获取repo默认分支上的最新提交的tarball/zipball URL:

{
  repository(owner: "google", name: "gson") {

    defaultBranchRef {
      target {
        ... on Commit {
          tarballUrl
          zipballUrl
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

使用搜索查询,您可以使用以下内容:

{
  search(query: "example", type: REPOSITORY, first: 20) {
    repositoryCount
    edges {
      node {
        ... on Repository {
          defaultBranchRef {
            target {
              ... on Commit {
                zipballUrl
              }
            }
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

使用,下载该搜索的所有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 {}
Run Code Online (Sandbox Code Playgroud)