Get GitHub total organisation commits by commiter

Published: 4 years ago web dev

For some reason, GitHub doesn't show you stats at an organisational level. I have been interested in seeing total organisational commits by committer for a while now so decided to grab this data from the GitHub API. Turns out, as always, it's not quite that simple.

To do this, the GitHub API has a rather promisingly named statistics api per repository. Alas in my situation this could not be relied upon as a number of commits (some of which were mine, tsk) were committed with an email address that does not match that of a GitHub profile. In such situations, no statistics get recorded for that commit! That also explains why the GitHub website often misreports stats for our org. Turns out committing with your GitHub associated email really is a good idea.

Anyway that meant doing things the more laborious way using the commits API. That does at least return everything but those results are also paginated so a bit of recursion is needed to fetch all the results per call.

From there it was just a case of getting the full list of repos for the organisation, looping through each one, then getting and summing the commits per repo.

Here is the python code for those who are interested. I am not a python expert. In fact I had some issues with python (well the amazingly named 'HTTPPasswordMgrWithDefaultRealm' to be precise), but I'll save them for another day.

If you want to try it yourself, you need to get an access token from GitHub. I had to give it full read repo rights and read organisation rights to get it to work correctly.