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

标签 git api github graphql github-api

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

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

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

{
  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
              }
            }
          }
        }
      }
    }
  }
}

使用 下载该搜索的所有 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 {}

关于git - 如何通过 GraphQL API 搜索下载 Github 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47458143/

相关文章:

git - 文件在 github 桌面中显示差异

node.js - 如何将 npm 包更新到最新提交?

python - 安装 pybrain

git - 将 git 项目从一个 Visual Studio Online 帐户移动到另一个 Visual Studio Online 帐户

linux - 如何在 Ubuntu 的 IDEA 中设置 git 方式?

api - flutter : How To Convert Future<String> to String?

git - Gitosis 可以强制执行正确的用户名/电子邮件吗?

swift - 解码简单的 API 数组 Swift

api - 如何使用 Telegram API 通过给定的 joinlink 获取私有(private) channel 的 chatid?

github - GitHub 中的 .editorconfig 文件