Created
January 16, 2023 10:10
-
-
Save ndemengel/3507a328333c2c1aabc5e04a8f640c9a to your computer and use it in GitHub Desktop.
Simple script outputting who likely has the most knowledge about an area of your code base
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
#!/bin/bash | |
## | |
# Outputs the top 10 committers on the provided area, for the period provided, | |
# based on the number of commits, in the form of 4 columns: | |
# Lines added, Lines deleted, Number of commits, Author | |
# (This allows for easily re-sorting the output by piping it into `sort -nr -k COLUMN_NUMBER`) | |
# | |
# Tip: replace tabs with commas everywhere below to output valid CSV content. | |
## | |
## | |
# Sample output: | |
# $ ./who-knows-about.sh some/area/of/your/repo 2022-09-01 | |
# Lines added Lines deleted Commits Author | |
# 5635 1813 91 "Jane Doe <jane.doe@acme.com>" | |
# 1283 874 79 "Someone Else <someone@example.com>" | |
# ... | |
## | |
readonly PATH_WITHIN_REPO=$1 | |
readonly AFTER_DATE=$2 | |
if [[ -z "$PATH_WITHIN_REPO" || -z "$AFTER_DATE" ]]; then | |
>&2 echo -e "Usage $0 PATH_WITHIN_REPO AFTER_DATE\n\twith AFTER_DATE being a date following the format YYYY-MM-DD" | |
exit 1 | |
fi | |
readonly SHORTLOG="$(git shortlog --no-merges -se --after="$AFTER_DATE" -- "$PATH_WITHIN_REPO" | sort -nr | head -n 10 | awk '{printf $1 "\t\t\""; for (i=2; i<NF; i++) printf $i " "; print $NF "\"" }')" | |
echo -e "Lines added\tLines deleted\tCommits\t\tAuthor" | |
IFS=$'\n' | |
for shortlog_entry in $SHORTLOG; do | |
AUTHOR="$(echo "$shortlog_entry" | sed -E 's/.*<(.*?)>.*/\1/')" | |
git log --no-merges --numstat --author="$AUTHOR" --after="$AFTER_DATE" -- "$PATH_WITHIN_REPO" | echo -e "$(awk 'NF==3 {plus+=$1; minus+=$2} END {printf("%d\t\t%d\n", plus, minus)}')\t\t$shortlog_entry" | |
done | |
unset IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment