我们如何使用github graphQL API列出仓库中的所有分支?

时间:2019-04-03 05:05:12

标签: github-api github-graphql

首先,我要检查回购中是否已存在分支。我需要先查看所有打开的分支。

query searhbranches { 
repositoryOwner(login: "username"){
repository(name: "config-replica"){
name
[branches] // something like this but its not available
}
}
}

1 个答案:

答案 0 :(得分:1)

您想查看refs内的repository节点。这是一个对我有用的示例查询:

{
  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"
          },
          ...
        ]
      }
    }
  }
}
...