【问题标题】:How to get all repos that contain a certain branch on Github's GraphQL API如何在 Github 的 GraphQL API 上获取包含某个分支的所有 repos
【发布时间】:2018-07-25 04:34:27
【问题描述】:

我有很多存储库,其中一些包含同名的分支。我希望能够获取包含特定分支名称的所有存储库。这是我到目前为止所拥有的,但我似乎无法弄清楚如何添加必要的查询。

{
  repositoryOwner(login: "dev") {
    repositories(first: 1) {
      nodes {
        name
        refs(first: 15, refPrefix: "refs/heads/") {
          edges {
            node {
              name
            }
          }
        }
      }
    }
  }
}

任何帮助将不胜感激。

【问题讨论】:

    标签: github github-api github-graphql


    【解决方案1】:

    一种方法是请求所有具有qualifiedName 的引用作为<branch_name> 的存储库。然后在您的客户端删除所有空结果:

    {
      repositoryOwner(login: "JakeWharton") {
        repositories(first: 100) {
          nodes {
            ref(qualifiedName: "gh-pages") {
              repository {
                name
                description
              }
            }
          }
        }
      }
    }
    

    Try it in the explorer

    使用 & 排除null 结果将是:

    curl -s -H "Authorization: token YOUR_TOKEN" \
         -d '{ 
              "query": "{ repositoryOwner(login: \"JakeWharton\") { repositories(first: 100) { nodes { ref(qualifiedName: \"gh-pages\") { repository { name } } } } } }"
          }' https://api.github.com/graphql | \
          jq -r '.data.repositoryOwner.repositories.nodes[] | select(.ref != null) | .ref.repository.name'
    

    如果有超过 100 个 repos,你将不得不去 through pagination

    您也可以使用aliases,以防您需要在单个存储库(或其中一个)中查找分支名称的组合。例如寻找分支gh-pages & 1.0

    {
      repositoryOwner(login: "JakeWharton") {
        repositories(first: 100) {
          nodes {
            branch1: ref(qualifiedName: "1.0") {
              repository {
                name
                description
              }
            }
            branch2: ref(qualifiedName: "gh-pages") {
              repository {
                name
                description
              }
            }
          }
        }
      }
    }
    

    Try it in the explorer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-19
      • 2021-11-23
      • 2020-03-16
      • 2022-08-19
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多