Last active
April 8, 2021 20:46
-
-
Save jlaustill/bdd34c83b41913cfec3b25b32720c943 to your computer and use it in GitHub Desktop.
Get the user stats for the previous month from a git repo
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
#!/usr/bin/env bash | |
format=${1:-pretty} | |
#if [[ "$OSTYPE" == "linux-gnu" ]] | |
#then | |
#from=$(date -d "last month" +"%d %b %Y") | |
#to=`date +"%d %b %Y"` | |
#else | |
#from=`date -v-1m` | |
#to=`date` | |
#fi | |
users=$(git shortlog -sn --no-merges | awk '{printf "%s %s\n", $2, $3}') | |
IFS=$'\n' | |
# colors | |
WHITE='\e[97m' | |
GREEN='\e[32m' | |
RED='\e[31m' | |
LIGHT_MAGENTO='\e[95m' | |
if [[ ${format} != 'pretty' ]] | |
then | |
echo -e "User name;Files changed;Lines added;Lines deleted;Total lines (delta);Add./Del. ratio (1:n);Commit count" | |
else | |
printf "${WHITE}%-30s | %-15s | %-15s | %-15s | %-20s | %-21s | %-15s\n" \ | |
"User name" "Files changed" "Lines added" "Lines deleted" "Total lines (delta)" "Add./Del. ratio (1:n)" "Commit count" | |
fi | |
for userName in $users | |
do | |
result=$(git log --author="$userName" --no-merges --shortstat \ | |
| grep -E "fil(e|es) changed" \ | |
| awk '{files+=$1; inserted+=$4; deleted+=$6; delta+=$4-$6; ratio=deleted/inserted} END {printf "%s;%s;%s;%s;%s", files, inserted, deleted, delta, ratio }' -) | |
countCommits=$(git shortlog -sn --no-merges --author="$userName" | awk '{print $1}') | |
if [[ ${result} != ';;;;' ]] | |
then | |
if [[ ${format} != 'pretty' ]] | |
then | |
echo -e "$userName;$result;$countCommits" | |
else | |
IFS=';' read -r -a resultsArr <<< "$result" | |
printf "%-30s | ${LIGHT_MAGENTO}%-15s ${WHITE}| ${GREEN}%-15s ${WHITE}| ${RED}%-15s ${WHITE}| %-20s | %-21s | %-15s\n" \ | |
"$userName" "${resultsArr[0]}" "${resultsArr[1]}" "${resultsArr[2]}" "${resultsArr[3]}" "${resultsArr[4]}" "$countCommits" | |
fi | |
fi | |
done |
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
#!/usr/bin/env bash | |
format=${1:-pretty} | |
if [[ "$OSTYPE" == "linux-gnu" ]] | |
then | |
from=$(date -d "last month" +"%d %b %Y") | |
to=`date +"%d %b %Y"` | |
else | |
from=`date -v-1m` | |
to=`date` | |
fi | |
users=$(git shortlog -sn --no-merges --since="$from" --before="$to" | awk '{printf "%s %s\n", $2, $3}') | |
IFS=$'\n' | |
# colors | |
WHITE='\e[97m' | |
GREEN='\e[32m' | |
RED='\e[31m' | |
LIGHT_MAGENTO='\e[95m' | |
if [[ ${format} != 'pretty' ]] | |
then | |
echo -e "User name;Files changed;Lines added;Lines deleted;Total lines (delta);Add./Del. ratio (1:n);Commit count" | |
else | |
printf "${WHITE}%-30s | %-15s | %-15s | %-15s | %-20s | %-21s | %-15s\n" \ | |
"User name" "Files changed" "Lines added" "Lines deleted" "Total lines (delta)" "Add./Del. ratio (1:n)" "Commit count" | |
fi | |
for userName in $users | |
do | |
result=$(git log --author="$userName" --no-merges --shortstat --since="$from" --before="$to" \ | |
| grep -E "fil(e|es) changed" \ | |
| awk '{files+=$1; inserted+=$4; deleted+=$6; delta+=$4-$6; ratio=deleted/inserted} END {printf "%s;%s;%s;%s;%s", files, inserted, deleted, delta, ratio }' -) | |
countCommits=$(git shortlog -sn --no-merges --since="$from" --before="$to" --author="$userName" | awk '{print $1}') | |
if [[ ${result} != ';;;;' ]] | |
then | |
if [[ ${format} != 'pretty' ]] | |
then | |
echo -e "$userName;$result;$countCommits" | |
else | |
IFS=';' read -r -a resultsArr <<< "$result" | |
printf "%-30s | ${LIGHT_MAGENTO}%-15s ${WHITE}| ${GREEN}%-15s ${WHITE}| ${RED}%-15s ${WHITE}| %-20s | %-21s | %-15s\n" \ | |
"$userName" "${resultsArr[0]}" "${resultsArr[1]}" "${resultsArr[2]}" "${resultsArr[3]}" "${resultsArr[4]}" "$countCommits" | |
fi | |
fi | |
done |
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
#!/usr/bin/env bash | |
format=${1:-pretty} | |
from=$2 | |
to=$3 | |
users=$(git shortlog -sn --no-merges --since="$from" --before="$to" | awk '{printf "%s %s\n", $2, $3}') | |
IFS=$'\n' | |
# colors | |
WHITE='\e[97m' | |
GREEN='\e[32m' | |
RED='\e[31m' | |
LIGHT_MAGENTO='\e[95m' | |
if [[ ${format} != 'pretty' ]] | |
then | |
echo -e "User name;Files changed;Lines added;Lines deleted;Total lines (delta);Add./Del. ratio (1:n);Commit count" | |
else | |
printf "${WHITE}%-30s | %-15s | %-15s | %-15s | %-20s | %-21s | %-15s\n" \ | |
"User name" "Files changed" "Lines added" "Lines deleted" "Total lines (delta)" "Add./Del. ratio (1:n)" "Commit count" | |
fi | |
for userName in $users | |
do | |
result=$(git log --author="$userName" --no-merges --shortstat --since="$from" --before="$to" \ | |
| grep -E "fil(e|es) changed" \ | |
| awk '{files+=$1; inserted+=$4; deleted+=$6; delta+=$4-$6; ratio=deleted/inserted} END {printf "%s;%s;%s;%s;%s", files, inserted, deleted, delta, ratio }' -) | |
countCommits=$(git shortlog -sn --no-merges --since="$from" --before="$to" --author="$userName" | awk '{print $1}') | |
if [[ ${result} != ';;;;' ]] | |
then | |
if [[ ${format} != 'pretty' ]] | |
then | |
echo -e "$userName;$result;$countCommits" | |
else | |
IFS=';' read -r -a resultsArr <<< "$result" | |
printf "%-30s | ${LIGHT_MAGENTO}%-15s ${WHITE}| ${GREEN}%-15s ${WHITE}| ${RED}%-15s ${WHITE}| %-20s | %-21s | %-15s\n" \ | |
"$userName" "${resultsArr[0]}" "${resultsArr[1]}" "${resultsArr[2]}" "${resultsArr[3]}" "${resultsArr[4]}" "$countCommits" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment