【问题标题】:How can we list all the branches in a repo using github graphQL api?我们如何使用 github graphQL api 列出 repo 中的所有分支?
【发布时间】:2019-04-03 20:28:13
【问题描述】:

我正在尝试检查 repo 中是否已经存在一个分支,首先我需要获取所有打开的分支。

查询搜索分支{ 
存储库所有者(登录:“用户名”){
存储库(名称:“配置副本”){
名称
[branches] // 类似这样的东西,但它不可用
}
}
}

【问题讨论】:

    标签: github-api github-graphql


    【解决方案1】:

    您想查看repository 中的refs 节点。这是一个适用于我的示例查询:

    {
      repository(owner: "desktop", name: "desktop") {
        refs(first: 50, refPrefix:"refs/heads/") {
          nodes {
            name
          }
        }
      }
    }
    

    这是它返回的内容:

    {
      "data": {
        "repository": {
          "refs": {
            "nodes": [
              {
                "name": "add-lfs-path-lookup"
              },
              {
                "name": "add-notes-lookup-to-parser"
              },
              {
                "name": "ahead-behind-toggle-spike"
              },
              {
                "name": "all-stash-functions"
              },
              ...
            ]
          }
        }
      }
    }
    ...
    

    【讨论】:

    • 它有效,我也能得到分支的名字。希望我也能改变它。谢谢@Brendon。
    • 如果您对解决方案感到满意,别忘了将其标记为已回答!
    猜你喜欢
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 2020-03-26
    • 2013-01-01
    • 1970-01-01
    • 2020-01-08
    • 2016-02-22
    • 2014-11-02
    相关资源
    最近更新 更多