15

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.)

dumbledad
  • 16,305
  • 23
  • 120
  • 273
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139

1 Answers1

4

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.):

Api usage

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

Community
  • 1
  • 1
nmanh
  • 325
  • 2
  • 14