Use Github API to fetch number of commits per year per user

Viewed 22

I'm trying to use the GitHub API to analyse a large repository. For that I want to get the number of commits per user and per year to build a table that looks like this:

user year1_commits year2_commits ...
abc 500 700 ...
ghf 0 700 ...

I fetched the list of all contributors using the /repos/{owner}/{repo}/contributors API, however the only way I found so far to fetch yearly contributions is by using this GraphQL:

query { 
    user(login: "${username}") {
        name
        email
        createdAt
        contributionsCollection(from: "${year}-01-01T00:00:00Z", to: "${year}-12-31T00:00:00Z") {
        commitContributionsByRepository(maxRepositories: 100) {
            repository {
            nameWithOwner
            }
            contributions {
            totalCount
            }
        }
        }
    }
}

The problem with this approach is that it requires fetching the data for each year individually, hence increasing the number of API calls required.

Is there a better way to get this information?

0 Answers
Related