Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github API: Check if a branch or repository contains a commit

Can I use the Github API to check if a certain repository contains a certain commit?

At first glance, it seems that the get a single commit API call should work, returning 404 if there is no such commit in the repository. But that is not true: It seems that this call will run successful on commits that are present in forked repositories (possibly due to a pull request). (This effect can also be observed in the regular web interface; this particular commit has not been pulled into that repository yet.)

like image 296
Joachim Breitner Avatar asked May 21 '15 14:05

Joachim Breitner


1 Answers

Api GitHub search

For searching other repositories one can use the api, which finds commits via various criteria. (This method returns up to 100 results per page.):

  • https://developer.github.com/v3/search/#search-commits
  • Only the default branch is considered, mostly master

Api usage

  • GET /search/commits
  • q can be any kind of search term combination: https://help.github.com/articles/searching-commits/

Example parameters for q

  • hash:124a9a0ee1d8f1e15e833aff432fbb3b02632105 Matches commits with the hash 124a9a0ee1d8f1e15e833aff432fbb3b02632105.
  • parent:124a9a0ee1d8f1e15e833aff432fbb3b02632105 Matches children of 124a9a0ee1d8f1e15e833aff432fbb3b02632105.

further parameters, like sorting, ordering can be found in the documentation above.

Usage example per hash:

  • example call https://api.github.com/search/commits?q=<searchterm>+<searchterm2>
  • specific call: https://api.github.com/search/commits?q=repo:adejoux/kitchen-wpar+hash:0a3a228e5b250daf06f933b35b3f0eafc715be4f

You need to add an special header, because the api is available for developers to preview

header to add: application/vnd.github.cloak-preview

like image 57
nmanh Avatar answered Oct 15 '22 01:10

nmanh