Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

337
Vistas
Is there a way to fetch the number of contribution of GitHub profile in Javascript?

Is there a way to fetch the number of contributions in the last year using Javascript (client-side)? Note that number is for the public and private repository

enter image description here

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Use a GraphQL query (GitHub API v4) and a ContributionsCollection object.

Define from by now minus one year, and to by now.

   var to = new Date();
   var year  = to.getFullYear();
   var month = to.getMonth();
   var day   = to.getDate();
   var from = new Date(year - 1, month, day);

Use graphql.js to then call, as in here:

query ContributionsView($username: String!, $from: DateTime!, $to: DateTime!) {
  user(login: $username) {
    contributionsCollection(from: $from, to: $to) {
      totalCommitContributions
      totalIssueContributions
      totalPullRequestContributions
      totalPullRequestReviewContributions
    }
  }
}

Once the script works outside your Blogger page, you can include it with a <script src=...> element.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I've tried many solutions and I improved one to get the following which works the best for me:

  1. Create a function in Javascript
function get_contribution() {
    profile_url = "https://cors-anywhere.herokuapp.com/https://github.com/users/USERNAME/contributions";

    var xhr = new XMLHttpRequest();
    xhr.responseType = 'document';

    xhr.open('GET', profile_url, true);
    xhr.onload = function () {
        if (this.status == 200) {
            var response = xhr.responseXML.getElementsByClassName('f4 text-normal mb-2')[0].innerText;
            // get only the numbers in response
            contribution = response.replace(/[^0-9]/g, '');
            
            // The number of contributions is now saved in the contribution variable
        }
    };
    xhr.send();
}
  • Change USERNAME to the GitHub username you want
  • Note that you have to use "cors" or it won't work
  1. Now you can use that function anywhere but in my case, I will call it on page load and set it somewhere in the HTML:
onload = function(){
    get_contribution();
  } 
about 4 years ago · Juan Pablo Isaza Denunciar

0

I suggest using the unofficial Github Contributions API located at this site

Here is an example

async function getContributions(username) {
  var data = await (await fetch(`https://corsanywhere.herokuapp.com/https://github-contributions-api.deno.dev/${username}.json`)).json();
  console.log(data.totalContributions)
}
getContributions("octocat") // Returns 0, as Octocat has zero contributions

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda