1

I've had a lot of success pulling README.md content from the github v4 syntax found in this issue as follows:

{
  repository(owner: "gitpoint", name: "git-point") {
    defaultBranchRef {
      name
    }
    object(expression: "master:README.md") {
      ... on Blob {
        text
      }
    }
  }
}

My issue comes when defaultBranchRef.name is not master. We can expect this to be the case more frequently moving forward as people move away from that naming convention for various reasons.

How do I change the expression to reference the repo's default branch name if I don't know it till I query? Or must I make 2 queries per repo?

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
carlism
  • 158
  • 1
  • 6

1 Answers1

4

You can use HEAD:[path] as expression to get the default branch :

{
  repository(owner: "gitpoint", name: "git-point") {
    object(expression: "HEAD:README.md") {
      ... on Blob {
        text
      }
    }
  }
}
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159