Github API: how to view open commits on a specific branch?


#1

I am looking for functionality in the github api, to see if there are still open commits on specific branch.

With open commits, I mean all commits that aren’t yet merged with the default branch.

I tried to use the “list branches” api (https://developer.github.com/v3/repos/branches/#list-branches), but this doesn’t return any information on commits.

Note: I posted the same question on stackoverflow (https://stackoverflow.com/questions/51656981/github-api-how-to-view-open-commits-on-a-specific-branch) and github.community.com (https://github.community/t5/How-to-use-Git-and-GitHub/Github-API-how-to-view-open-commits-on-a-specific-branch/m-p/11415#M3712)


#2

I’m not clear on what you’re trying to determine, but the github API isn’t designed to answer this type of question directly.

You appear to be looking for information about the relationship between two git branches. Your question can be answered directly in git – i.e. you don’t need to utilize any of the GitHub extras (like issues or PRs). GitHub can provide you the same underlying git information. (See the Git Data section of the API.)

My suggestion would be to:

  1. use the git cli to refine exactly what you want (could be git log or git diff output).
  2. determine how to get that answer using low level plumbing commands
  3. determine how to use the API to obtain the same information from GitHub.

Good luck!