Diong
Diong

Reputation: 1

How to find all the commits of an organization in github?

Currently now github allows me to find the commits of a repo but in an organization there are many repos using this below

https://api.github.com/repos/OWNER/REPO/commits

I want to find the total of all the repos without looping through and summing all of them. Is there a faster way to get the total commits of an organization

i tried https://api.github.com/repos/OWNER/REPO/commits this for every repo but the time taken to run is very long so i wanted to find a better alternative.

Upvotes: -1

Views: 416

Answers (1)

Schwern
Schwern

Reputation: 164809

A faster option might be to use the Github API to list all public repositories of an organization. For each repository only clone the commits using git clone --filter=object:type=commit. Then use git to examine the commits.

Here's some pseudo code to explain how to count every commit in an organization.

num_commits = 0
for repo in org.repos
  git clone --filter=object:type=commit repo.url
  cd into repo
  num_commits += git rev-list --all --count

This has the potential to be very efficient because the commit objects are very small and cloning is very efficient. Much more efficient than paging through every commit with a JSON API.

Upvotes: 0

Related Questions