Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github api: How to efficiently find the number of commits for a repository?

I want to find the number of commits done to specific github projects, and within them to specific files. I checked the github api docs but only found an API for actually returning all commits. This would be very inefficient since I have to do multiple api calls for paging thru all commits.

Anyone has a better idea?

like image 997
drorw Avatar asked Apr 10 '13 07:04

drorw


People also ask

What GitHub repo has the most commits?

The answer: Commited Commited has over 3,000,000 commits, making it the GitHub, most repo commits, world record holder!

How many commits can git handle?

1 accepted. Hi @Diliup-G , We don't have a limit on the number of commits per repository.


2 Answers

Update May 2013: see "File CRUD and repository statistics now available in the API"

You now can Get the last year of commit activity data

GET /repos/:owner/:repo/stats/commit_activity

Returns the last year of commit activity grouped by week. The days array is a group of commits per day, starting on Sunday.

Not completely what you are looking for, but closer.


Original answer (April 2010)

No, the current API doesn't support a 'log --all' for listing all commmits from all branches.

The only alternative is presented in "Github API: Retrieve all commits for all branches for a repo", and list through all pages of all commits, branch after branch.

This seems so cumbersome than another alternative would actually to clone the Github repo and apply git commands on that local clone!
(mainly git shortlog)


Note: you can also checkout that python script created by Arcsector.

like image 135
VonC Avatar answered Sep 28 '22 14:09

VonC


With GraphQL API v4, you can get total commit count per branch with totalCount for each branch:

{
  repository(owner: "google", name: "gson") {
    name
    refs(first: 100, refPrefix: "refs/heads/") {
      edges {
        node {
          name
          target {
            ... on Commit {
              id
              history(first: 0) {
                totalCount
              }
            }
          }
        }
      }
    }
  }
}

Test it in the explorer

like image 40
Bertrand Martel Avatar answered Sep 28 '22 13:09

Bertrand Martel