Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API: Identify the branches that contain a given commit

Tags:

github

Given the SHA of a specific commit in my repo, I want to identify the branches which contain the commit, using the GitHub API.

I'm aware I can do this locally using git directly in a variety of ways, including

git branch --contains <commit>

but this is for an integrated page that's pulling data from several platforms, so I really need to be using the API.

This question had an accepted answer saying this wasn't possible back in 2013, but I'm hoping something along these lines has been added to the API since.

Is anyone aware of a way to get this information short of querying for a list of ALL commits in the branches of interest and iterating through them to compare?

like image 697
S McCrohan Avatar asked May 01 '15 18:05

S McCrohan


People also ask

How do you find which branch a commit belongs to?

It is based on "Find merge commit which include a specific commit". Find when a commit was merged into one or more branches. Find the merge commit that brought COMMIT into the specified BRANCH(es). Specifically, look for the oldest commit on the first-parent history of BRANCH that contains the COMMIT as an ancestor.

How do I search for a commit in GitHub?

To search commits in a specific repository, use the repo qualifier. gibberish user:defunkt matches commit messages with the word "gibberish" in repositories owned by @defunkt. test org:github matches commit messages with the word "test" in repositories owned by @github.


Video Answer


1 Answers

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 (https://github.com/:user/:repo/commit/:sha) and getting the commit-branches div.

Finally, Github's Support is great, so you should ask them - worst-case scenario is they tell you it's not implemented, but maybe they put it on the TO-DO list.

like image 51
mgarciaisaia Avatar answered Dec 01 '22 16:12

mgarciaisaia