Retrieving the commit message and hash from a set of Github commits

Viewed 230

I have a database of the links to GitHub commits (or hashes) of some projects. I want to do a sentiment analysis of commit comments (messages). I need to print the commit message of one given commit but from a big set of the projects.

However, how can I do this without cloning all of the projects and retrieving the information from the specific commits individually?

1 Answers

You can use the official GitHub REST API v3, specifically the commits endpoint of the Git database API and retrieve the commit as a JSON object. The syntax is the following:

GET /repos/:owner/:repo/git/commits/:commit_sha

Replace :owner, :repo and :commit_sha by correct values. For example:

GET https://api.github.com/repos/torvalds/linux/git/commits/8dc765d438f1e42b3e8227b3b09fad7d73f4ec9a

is the JSON representation of this commit: https://github.com/torvalds/linux/commit/8dc765d438f1e42b3e8227b3b09fad7d73f4ec9a

with a field message containing the commit message.

Related