Created
October 20, 2014 16:39
-
-
Save Janiczek/0aa9c7b262b3bf395b11 to your computer and use it in GitHub Desktop.
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 | |
# Will generate CSV file with your commits. Columns: | |
# repository | branch | date | hash | message | |
# The file will be sorted by the date, and rows made unique. | |
# Expects to be run in a directory in form: | |
# . | |
# |- repo 1 | |
# |- repo 2 | |
# |- ... | |
# \- repo N | |
# Will create a report file ./report-<CURRENT-DATE>.csv | |
# TODO is there a way to find out the name of the branch the commit was commited to? | |
# (as opposed to being found in, which is what we check for now) | |
# TODO date range? | |
AUTHOR="Martin Janiczek"; | |
PWD=`pwd`; | |
TMPFILE="$PWD/commits.txt"; | |
DATE=`date +%Y-%m-%d`; | |
FILE="$PWD/report-$DATE.csv"; | |
function get_repos { | |
REPOS=`echo */`; | |
for REPO in $REPOS; | |
do | |
REPO=${REPO%%/}; # ditch the / | |
echo "$REPO"; | |
done; | |
} | |
function get_branches { | |
BRANCHES=`git for-each-ref --format='%(refname)' refs/{heads,remotes}/`; | |
for BRANCH in $BRANCHES; | |
do | |
BRANCH=$(basename "$BRANCH"); | |
echo "$BRANCH"; | |
done; | |
} | |
function list_commits { | |
SHA=`git rev-parse --short "$BRANCH" 2>/dev/null`; | |
IFS=$'\n'; | |
COMMITS=`git shortlog --author="$AUTHOR" --format="%ai%x09%h%x09%s" "$SHA" 2>/dev/null | tail -n+2 | ghead -n-1`; | |
for COMMIT in $COMMITS; | |
do | |
COMMIT=`echo "$COMMIT" | gsed "s/ //"`; | |
echo -n "."; | |
echo -e "$REPO\t$BRANCH\t$COMMIT" >>"$TMPFILE"; | |
done; | |
echo ""; | |
} | |
for REPO in `get_repos`; | |
do | |
cd "$REPO"; | |
for BRANCH in `get_branches`; | |
do | |
echo "looking at $REPO/$BRANCH"; | |
list_commits; | |
done; | |
cd ..; | |
done; | |
sort -t $'\t' -k3,3 -u "$TMPFILE" >"$FILE"; | |
rm -rf "$TMPFILE"; | |
echo "Done writing to $FILE"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment