Last active
February 24, 2023 13:40
-
-
Save bricss/4daffede03a4c63d3034b9aab35363bc to your computer and use it in GitHub Desktop.
Generates monthly Git reports
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 | |
# Generates monthly Git reports | |
# Usage: `sh git-report.sh [ample]` | |
author=$(git config user.name) | |
ample=$(expr "$1" == 'ample') | |
date=$(date +%Y-%m-%d) | |
foretime=$(date +%Y-%m-01) | |
fullpath="$PWD" | |
target=reports/report-${date} | |
rm -rf ${target} | |
mkdir -p ${target} | |
function report { | |
cname=$(git rev-parse --show-toplevel | xargs basename) | |
cpath=${fullpath}/${target}/${cname}-${date} | |
changelog=${cpath}.csv | |
delta=${cpath}-diff.txt | |
git log --all --author="$author" --date=short --no-merges --pretty=format:%h,%ae,%ad,%s, --reverse --shortstat --since=${foretime} | paste - - - | tr -d '\t' > ${changelog} | |
if [[ ! -s ${changelog} ]]; then | |
rm -f ${changelog} | |
else | |
git log --all --author="$author" --patch-with-raw --reverse --since=${foretime} > ${delta} | |
if which 7z &> /dev/null; then | |
(($ample)) \ | |
&& git log --all --author="$author" --format='' --name-only --reverse --since=${foretime} \ | |
| xargs -n1 | sort -u | uniq -i | xargs -r 7z a -mx -t7z ${cpath}.7z ${changelog} ${delta} \ | |
|| 7z a -mx -t7z ${cpath}.7z ${changelog} ${delta} | |
else | |
(($ample)) \ | |
&& git log --all --author="$author" --format='' --name-only --reverse --since=${foretime} \ | |
| xargs -n1 | sort -u | uniq -i | xargs -r tar --ignore-failed-read -cJvf ${cpath}.tar.xz --directory ${cpath%/*} ${changelog##*/} ${delta##*/} --directory "$PWD" \ | |
|| tar --ignore-failed-read -cJvf ${cpath}.tar.xz --directory ${cpath%/*} ${changelog##*/} ${delta##*/} | |
fi | |
fi | |
} | |
function traverse { | |
if [[ -d '.git' ]]; then | |
report | |
else | |
for dir in */; do | |
if [[ -d "$dir" ]]; then | |
pushd "$dir" | |
traverse | |
popd | |
fi | |
done | |
fi | |
} | |
traverse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment