How to get the tag for a PR

The GitHub UI for a merged PR has this information:
title="v1.178.2 was the first Git tag to include this PR"

How can I get that same info from the API?
I can get PRs easily enough, but I don’t know how to get at the release tag from there.
(REST API would be fine too.)

query {
  repository(owner: "...", name: "...") {
    pullRequests(states: MERGED, first: 100) {
      edges {
        node {
          headRef {
          mergeCommit {

That is not a native thing from Github. We at refined-github added it. (I wish there was a direct api)

You can see how we did it here

1 Like

Oh my, this looks very useful. I often forget I’m using refined-github — it’s just how GitHub should be!

I see you scrape the HTML from<owner>/<repo>/branch_commits/ – does this mean that this info isn’t forthcoming from the APIs at all?

Responding to myself … according to this StackOverflow answer, indeed not:

None of the Repository Commit, Git Commit nor Git References endpoints provide that data, so I think the API just doesn’t do it.

But the website shows that data, so if you desperately need it you could try scraping the commit’s page ( ) and getting the commit-branches div.

In my case I want to get this info programmatically from a large number of private repos, so scraping the website (and negotiating OTP) doesn’t work.

I’ve just come across a PR that shows a beta release which is not last-child — it is in fact the 3rd-last child on the .../branch_commits/... page. Is this a bug?

Should I expect to ever see -beta tags?


:+1: Sure open an issue if you see a bug.

OK opened this one: Tag widget ("... was the first Git tag to include this PR") finds the third-last tag · Issue #4259 · sindresorhus/refined-github · GitHub

FWIW, it looks like this solves my use case: tagName = repo.git.name_rev("--name-only", merge_commit).
That’s doing git name-rev on a local clone, with the mergeCommit result from the query above.