Skip to content

Instantly share code, notes, and snippets.

@just-paja
Last active December 4, 2023 18:49
Show Gist options
  • Save just-paja/a1b3dedc2b50530cbff9c0d9782e75cb to your computer and use it in GitHub Desktop.
Save just-paja/a1b3dedc2b50530cbff9c0d9782e75cb to your computer and use it in GitHub Desktop.
Calculate production code contributions from git
#!/usr/bin/env bash
# This script calculates author contributions. It counts all git indexed lines
# that somehow contribute to the production value. All test files, lock files
# and binary files are excluded. Also it prints file names as progress
# indicator.
#
# * Counts only living contributions
# * Lines of code that have been changed are attributed to the last author
# * Misconfigured git names will lead to scrambled contributions
files=$(git ls-files\
| grep -vE '(spec|__tests?__|\/tests?\/)' \
| grep -vE '(package-lock.json|yarn.lock|^\.yarn)')
for file in $files; do
if file $file | grep -q "text"; then
echo -en "\033[1K\rChecking ${file:0:$(($(tput cols) - 16))}..." >&2
git blame --date=format: $file \
| cut -d '(' -f2 \
| cut -d ')' -f1 \
| rev \
| cut -d ' ' -f 2- \
| xargs -L 1 echo \
| rev
echo -en "\033[1K\r" >&2
fi
done | sort | uniq -c | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment