rahil sharma
rahil sharma

Reputation: 73

How can we list all the branches in a repo using github graphQL api?

I am trying to check if a branch already exists in repo for that first I need to get all the open branches present.

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

Upvotes: 5

Views: 2789

Answers (1)

Brendan Forster
Brendan Forster

Reputation: 2718

You want to look at the refs node inside repository. Here's an example query that works for me:

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

This is what it returns:

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

Upvotes: 6

Related Questions