Skip to content

Instantly share code, notes, and snippets.

@imranomari
Created January 24, 2020 10:40
Show Gist options
  • Save imranomari/e5331d62af7c0cba4bc6f69ea6ed4e65 to your computer and use it in GitHub Desktop.
Save imranomari/e5331d62af7c0cba4bc6f69ea6ed4e65 to your computer and use it in GitHub Desktop.
#!/bin/bash
cd $1
file_count=$(git ls-tree -r --name-only HEAD | wc -l | xargs)
current_file=1
default_since='2019-01-01'
default_fixes_pattern='fix|revert|bug'
echo "Collecting stats of repository files since ${3:-$default_since}"
echo "--> total files: $file_count"
# START CSV
echo "filename, lines, changes, active_days, authors, updated_at, fixes" > $2
git ls-tree -r --name-only HEAD | while read filename; do
changes=$(git log --pretty='format: %s' --since=${3:-$default_since} -- "$filename" | wc -l)
active_days=$(git log --pretty='format: %ad' --date=short --since=${3:-$default_since} -- "$filename" | sort -u | wc -l)
fixes=$(git log --pretty='format: %s' --since=${3:-$default_since} -- "$filename" | grep -E -i "${3:-$default_fixes_pattern}" | wc -l)
authors=$(git log --pretty='format: %an' --since=${3:-$default_since} -- "$filename" | sort -u | wc -l)
lines=$(wc -l "$filename" | awk '{print $1;}')
updated=$(git log -1 --pretty='format: %ad' --date=short -- "$filename")
changes=$((changes))
echo -ne "--> processed: $current_file \r\c"
echo "$filename, $lines, $changes, $active_days, $authors, $updated, $fixes" >> $2
current_file=$((current_file+1))
done
# END CSV
echo -ne "\n"
echo "--> DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment