【问题标题】:How to download Github repositories via GraphQL API search?如何通过 GraphQL API 搜索下载 Github 存储库?
【发布时间】:2017-11-23 14:47:27
【问题描述】:

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

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

这是我当前返回存储库名称和描述 (try to run here) 的代码:

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

【问题讨论】:

    标签: git api github graphql github-api


    【解决方案1】:

    您可以使用以下内容在 repo 的默认分支上获取最新提交的 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 -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 {}
    

    【讨论】:

    • 如何获取我指定的特定分支的 zip?
    【解决方案2】:

    @tharinduwijewardane

    JFYI,您可以通过此查询下载特定分支的 zip

    repository(owner: "owner", name: "repo name") {
      object(expression: "branch") {
        ... on Commit {
          zipballUrl
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      • 2015-07-06
      • 2021-12-30
      相关资源
      最近更新 更多