Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save devded/3400cdde102aa77e94ebfdbd1576e593 to your computer and use it in GitHub Desktop.
Save devded/3400cdde102aa77e94ebfdbd1576e593 to your computer and use it in GitHub Desktop.
Get total count of contributions in gitlab for current year

Just paste it into the browser console, and it will count contributions for you.

const currentYear = String(new Date().getFullYear());
const targetElement = document.querySelector(".col-12.calendar-block.gl-my-3");

if (targetElement) {
  const userContribElements = Array.from(document.querySelectorAll(".user-contrib-cell"));

  const totalContribution = userContribElements.reduce((acc, el) => {
    const accumulatedValue = isNaN(+acc) ? 0 : acc;
    const titleParts = el.getAttribute("title").trim().split(" ");
    const isValidValue = titleParts.length > 1 && !isNaN(+titleParts[0]) && titleParts.join(" ").includes(currentYear);
    const contribution = isValidValue ? +titleParts[0] : 0;

    return accumulatedValue + contribution;
  }, 0);

  const pElement = document.createElement("p");
  pElement.innerHTML = `<strong>${totalContribution}</strong> contributions in <strong>${currentYear}</strong>`;

  pElement.style.textAlign = "center";
  targetElement.appendChild(pElement);
} else {
  console.error("Target element not found");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment