DEV Community

Cover image for I Built a Leaderboard to Compare How Much Code I Write With My Friends
Yaroslav H
Yaroslav H

Posted on

I Built a Leaderboard to Compare How Much Code I Write With My Friends

I wanted a simple thing: a chart of how much code I write each day, commits and lines added and deleted, and a board where I could compare that with a few friends. It turned into a small puzzle about what GitHub actually knows, so here is how it works.

Monthly Lines-per-Day Chart on the Personal Page

What GitHub gives you

Commits per day: yes. The contribution calendar (the green squares) is available through the GraphQL API as contributionsCollection. One call per person gives a whole year of daily counts. That part is easy.

Lines per day: no. GitHub does know lines added and deleted, but only through the stats/contributors endpoint, and it answers per repo and per week, not per day. It also returns 202 Accepted the first time you ask for a repo while it computes the numbers in the background, so you have to come back later.

Private repos: mostly no. An app that only asks for your public profile sees your public repos. Your private and work repos show up as a count of "restricted contributions" and nothing else. I wrote up the details of why there is no stats-only permission here.

So from GitHub alone you get daily commits, weekly lines, and nothing about private work.

How Gitstats does it

Your own computer has the full history of every repo you've cloned, so the real per-day numbers are one git command away:

git log origin/main --no-merges --numstat --author=you@example.com --since="1 year ago"
Enter fullscreen mode Exit fullscreen mode

--numstat prints added and deleted lines per file for each commit, and each commit has a date. Group by day and you have lines per day, for public, private and work repos alike.

Gitstats has a small CLI that does exactly that, once a day in the background. It sends only the numbers per day and per week, plus a keyed hash of the repo's remote so the server can match the same repo across machines. No code, no file names, and repo names only if you turn them on. It's one file you can read before running it.

This way it can display your full detailed stats (lines per day, commits, repo activity) without token access to any of your repos.

Friends Leaderboard

What the numbers are (and aren't)

Lines include lockfiles, docs and generated code, and I count the default branch only. So the numbers are big and noisy, and they are not a measure of how good anyone's work is. For my friends and me it's a scoreboard and a way to notice patterns: which weekday I actually get things done, when a side project went quiet, how much changed when I started using coding agents. If you prefer, commits are one click away.

Personal Page Charts

Try it

  • Type your GitHub handle at https://gitstats.org and see your year in a few seconds, no sign-in (only public repo data).
  • Demo board: https://gitstats.org/demo
  • Sign in with GitHub for your own page and a crew, and run npx @yaroslavhaidash/gitstats-cli@latest link to add private repos.

It's open source under MIT: https://github.com/yaroslavhaidash/gitstats

I'm curious what other people would want from their own coding stats, or what's missing from this.

Top comments (0)