Last active
December 4, 2023 18:49
-
-
Save just-paja/a1b3dedc2b50530cbff9c0d9782e75cb to your computer and use it in GitHub Desktop.
Calculate production code contributions from git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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