6

Question from my comment here: How to check mergeability of a branches using the github api

Is it possible to check the mergeability of two branches using the github API without making a PR? I dont want to trigger anything by creating a PR, even if I immediately delete the PR afterwards.

Alex Yurkowski
  • 1,676
  • 1
  • 12
  • 26

1 Answers1

2

You can try and use the GitHub API compare commits (which can be used for branches), as I illustrated here.

That will give you a status:

  "status": "behind",
  "ahead_by": 1,
  "behind_by": 2,

If you see only ahead: the branch will be easily mergeable (fast-forward).
If you see both ahead and behind... there might be conflict, but it is harder to be sure.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This is the closest you're going to get without making a pull request – Brendan Forster Nov 29 '17 at 04:11
  • You can also hack it just by using a GET request on the `.../compare/base...feature-branch` and then scrape the resulting HTML for the `Can’t automatically merge.` string. This is obviously very brittle but is a decent way to sniff this out w/o requiring any repo mutation. – xanadont Nov 09 '20 at 19:00
  • @xanadont Interesting. The compare is the one I mentioned in https://stackoverflow.com/a/26962188/6309? – VonC Nov 09 '20 at 19:04
  • @VonC That's via the API. I mean to say, you can use the public web URL that you would normally load in a browser. AFAICT, you can't actually get from the API a definitive `true` or `false` whether a compare has merge conflicts or not. The hacky method I suggested does. But maybe I'm missing something? – xanadont Nov 09 '20 at 23:06