Created
October 27, 2023 16:28
-
-
Save davidkuster/b6bdf9b5d8b5bc53b5b21be349ea3e18 to your computer and use it in GitHub Desktop.
Script to report stats on a Git project. Who's been working nights and weekends? (Spoiler alert: this guy)
This file contains hidden or 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 | |
# Pass project dir as a param (could be '.' for the current dir) | |
cd $1 | |
if [ ! -d .git ]; then | |
echo "This is not a valid git directory." | |
exit 1 | |
fi | |
# Convert email to a case-insensitive regex pattern | |
case_insensitive_pattern() { | |
local email="$1" | |
local pattern="" | |
for (( i=0; i<${#email}; i++ )); do | |
char="${email:$i:1}" | |
if [[ "$char" =~ [a-zA-Z] ]]; then | |
lower=$(echo "$char" | tr '[:upper:]' '[:lower:]') | |
upper=$(echo "$char" | tr '[:lower:]' '[:upper:]') | |
pattern+="[$lower$upper]" | |
else | |
pattern+="$char" | |
fi | |
done | |
echo "$pattern" | |
} | |
# Get stats for the given developer | |
process_commits() { | |
local email="$1" | |
local pattern=$(case_insensitive_pattern "$email") | |
echo "$email:" | |
# Total commits | |
total_commits=$(git log --author="$pattern" --oneline | wc -l) | |
# Commits before noon | |
before_noon=$(git log --author="$pattern" --pretty=format:'%ad' --date=format:'%H:%M' | awk -F: '$1 < 12' | wc -l) | |
# Commits between noon and 5pm | |
noon_to_5pm=$(git log --author="$pattern" --pretty=format:'%ad' --date=format:'%H:%M' | awk -F: '$1 >= 12 && $1 < 17' | wc -l) | |
# Commits after 5pm | |
after_5pm=$(git log --author="$pattern" --pretty=format:'%ad' --date=format:'%H:%M' | awk -F: '$1 >= 17' | wc -l) | |
# Commits on weekends (note these might be double counting some of what's above) | |
weekend_commits=$(git log --author="$pattern" --pretty=format:'%ad' | grep -E '^(Sat|Sun)' | wc -l) | |
echo " Total commits: $total_commits" | |
echo " Commits before noon: $before_noon" | |
echo " Commits from 12-5pm: $noon_to_5pm" | |
echo " Commits after 5pm: $after_5pm" | |
echo " Commits on weekends: $weekend_commits" | |
echo "" | |
} | |
echo -e "Getting git statistics...\n" | |
# Get list of authors | |
authors=$(git log --format='%aE' | sort -uf) | |
# Process each author | |
while IFS= read -r author; do | |
process_commits "$author" | |
done <<< "$authors" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment