Skip to content

Instantly share code, notes, and snippets.

@bitmess
Created June 5, 2017 06:48
Show Gist options
  • Save bitmess/5de01f88c6e3db762119f290cacd8d74 to your computer and use it in GitHub Desktop.
Save bitmess/5de01f88c6e3db762119f290cacd8d74 to your computer and use it in GitHub Desktop.
export Projects's last day's commits
#!/bin/sh
Path="/Users/bitmess/Desktop/Git/Demo" #改为项目的全路径
Mans="bitmess bitgoodies" #所有的提交Author
########################################################################
function ToHtml(){
Content=`cat $1 | sed -n $2,$3"p"`
if [ -n "$Content" ]; then
Content=`echo "$Content" | sed -n 's/$/<br\/>/p' | sed 's/\(^@@.*@@\)/<br\/><br\/><div style="color:white;background-color:brown;">\1<\/div>/g' | sed 's/\(^diff --git.*\)/<span style=\"background-color:blue;color:white;\">\1<\/span>/g' | sed 's/\(^+.*\)/<span style=\"background-color:green;color:white;\">\1<\/span>/g' | sed 's/\(^-.*\)/<span style=\"background-color:red;color:white;\">\1<\/span>/g'`
Content="<html><body><code>$Content</code></body></html>"
echo "$Content"
return
fi
echo ""
}
function SplitDiff(){
if [ ! -n "$1" ] ;then
echo "file not empty"
return
fi
DestDir=~/Desktop/Splits
FilePath=$1
if [ -n "$2" ] ;then
DestDir=$2
fi
if [ -n "$DestDir" ] ;then
rm -rf $DestDir
fi
mkdir -p $DestDir
Arr=`cat $FilePath | sed -n '/diff --git/='`
Start=1
TotalLine=`cat $FilePath | wc -l`
TotalLine=$(($TotalLine))
index=1
for i in $Arr; do
End=$(($i-1))
Content=`ToHtml "$FilePath" "$Start" "$End"`
Start=$i
if [ -n "$Content" ]; then
echo "$Content" > $DestDir/$index.html
index=$(($index+1))
fi
done
Content=`ToHtml "$FilePath" "$Start" "$TotalLine"`
if [ -n "$Content" ]; then
echo "$Content" > $DestDir/$index.html
fi
}
########################################################################
cd $Path
Yesterday=`date -v-1d +%Y-%m-%d`
Date=`date +%Y-%m-%d`
if [ -n "$1" ] ;then
Yesterday=$1
fi
echo Log Date : $Yesterday
Dir=~/Desktop/$Date
if [ -n "$Dir" ] ;then
rm -rf $Dir
fi
mkdir -p $Dir
for Man in $Mans
do
Dest=$Dir/$Man.txt
MyDir=$Dir/$Man
mkdir -p $MyDir
git log --all --author=$Man -p --since="$Yesterday 00:00:00" --until="$Yesterday 23:59:59" --pretty=format:"%b" > "$Dest"
SplitDiff "$Dest" "$MyDir"
TotalLine=`cat $Dest | wc -l`
TotalLine=$(($TotalLine))
Content=`ToHtml "$Dest" 1 "$TotalLine"`
if [ -n "$Content" ]; then
echo "$Content" > $MyDir/result.html
fi
if [ -n "$Dest" ] ;then
rm -rf $Dest
fi
done
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment