Search code examples
githubgoogle-chrome-extensiongithub-api

How can you get how many contributions a user did today with the GitHub API


I am making a very simple chrome extension that displays the number of contributions you did today on GitHub. How can i get that number?


Solution

  • You could use Github GraphQL API to request contributionsCollection with a date range :

    query { 
      viewer { 
        contributionsCollection(from:"2020-05-05T00:00:00Z", to:"2020-05-05T00:00:00Z") {
          contributionCalendar{
            totalContributions
          }
        }
      }
    }
    

    For a specific user:

    query { 
      user(login:"krissemicolon") { 
        contributionsCollection(from:"2020-06-01T00:00:00Z", to:"2020-06-01T00:00:00Z") {
          contributionCalendar{
            totalContributions
          }
        }
      }
    }
    

    If using graphql API is not an option you could also parse the calendar svg, checkout this