Last active
November 11, 2015 21:16
-
-
Save kevinkreiser/a6bb46fc3cc2954a19f0 to your computer and use it in GitHub Desktop.
CSV Generator for Graphing Bytes of Code Since a Date in the Past
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
#!/bin/bash | |
#run this like: DAYS=365 ./code_timeline.sh https://github.com/org/repo1.git https://github.com/org/repo2.git | |
#note that the types of files it checks for code are hardcoded below | |
code='\.cc$|\.h$|\.cpp$|\.hpp$|\.lua$|\.py$|\.js' | |
: ${DAYS:?Please set DAYS environment variable to a number of days in the past youd like to capture} | |
#setup each repo | |
echo -n "day," | |
for url in ${@}; do | |
name=$(basename ${url}) | |
repo="${name%.*}" | |
echo -n "${repo}," | |
rm -rf ${repo} | |
git clone $url &> /dev/null #purposely dont get submodules | |
done | |
#for each day | |
current=-${DAYS} | |
while [ ${current} -lt 1 ]; do | |
#date to look for | |
echo | |
echo -n "$((DAYS+current))," | |
d=$(date -d "${current} days" +%Y-%m-%d) | |
((current++)) | |
#for each repo | |
for url in ${@}; do | |
#get in there and find the revision matching this date | |
name=$(basename ${url}) | |
pushd "${name%.*}" &> /dev/null | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
revision=$(git rev-list -n 1 --before="${d} 23:59" ${branch}) | |
bytes=0 | |
#do we have a revision that old | |
if [ ${revision} ]; then | |
#checkit out and see if we had code | |
git checkout ${revision} &> /dev/null | |
if [ "$(find . -type f | grep -E ${code})" != "" ]; then | |
#count the bytes | |
bytes=$(wc -c $(find . -type f | grep -E ${code}) | tail -n 1 | awk '{printf $1}') | |
fi | |
git checkout ${branch} &> /dev/null | |
fi | |
popd &> /dev/null | |
#add that number to the file | |
echo -n "${bytes}," | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment