Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 135 lines (115 sloc) 2.92 KB
#!/usr/bin/env bash
# Creates diffs with my changes in code from the last month for PKUP report
# PKUP stands for "Podwyższone Koszty Uzyskania Przychodu" in Polish
set -e
msg() {
tput setaf 2 # green text
echo ">>> $1"
tput sgr 0
sleep 1
}
showHelp() {
echo '
pkup is a script for generating PKUP reports
it creates *.diff files from the git repositories and creates *.docx document
usage:
-h shows help
-m "<message for the report>" generates a report with a provided message
-g generates a report with an empty message
'
}
setAfterDate() {
currentMonth=$(date +%m)
currentYear=$(date +%Y)
if [ $currentMonth -eq "1" ]; then
lastMonth=12
yearsToRemove=1
year=$(echo "$currentYear-$yearsToRemove" | bc)
else
monthsToRemove=1
lastMonth=$(echo "$currentMonth-$monthsToRemove" | bc)
year=$currentYear
fi
day=19
afterDate="$year-$lastMonth-$day"
}
saveDiff() {
setAfterDate
msg "saving diff for $1 commits from $afterDate"
cd $yDEV_PROJECTS_DIR/"$1"
gitUserName=$(git config user.name)
mkdir -p "$filePath"
git log --author="$gitUserName" -p --after="$afterDate" > "$filePath"/"$1"."$fileExtension"
}
removeDiffIfEmpty() {
if [ ! -s "$filePath"/"$1"."$fileExtension" ]
then
msg "no changes performed in $1 -> removing empty $1.$fileExtension file"
rm -f "$filePath"/"$1".$fileExtension
fi
}
parseRepos() {
for project in "${yDEV_PROJECTS_LIST[@]}"
do
saveDiff $project
removeDiffIfEmpty $project
done
}
loadConfiguration() {
if [ ! -f $HOME/.pkup.conf ]; then
if [ -f .pkup.conf ]; then
. .pkup.conf
fi
else
. $HOME/.pkup.conf
fi
}
setPythonScriptPath() {
if [ -f "/usr/local/bin/$pythonScriptName" ]; then
scriptPath="/usr/local/bin/"
elif [ -f $projectDir/$pythonScriptName ]; then
scriptPath="$projectDir/"
fi
}
saveReport() {
msg "saving report..."
cd $filePath
savedDiffFiles=$(ls | grep .$fileExtension)
filesDesc=$'\n\nPliki zawierające opis zmian:\n'
pythonScriptName="pkup_doc.py"
gitUserName=$(git config user.name)
setPythonScriptPath
python3 "$scriptPath""$pythonScriptName" \
--name "$gitUserName" \
--role "$yDEV_ROLE" \
--department "$yDEV_DEPARTMENT" \
--manager "$yDEV_MANAGER" \
--text "$reportText$filesDesc$savedDiffFiles"
}
main() {
loadConfiguration
gitUserName=$(git config user.name)
IFS=' ' eval 'gitUserNameArray=($gitUserName)'
dateFormat=$(date +'%Y%m')
filePath=$yDEV_REPORT_DIR""${gitUserNameArray[1]}"_"${gitUserNameArray[0]}"_"$dateFormat
fileExtension=diff
projectDir=$(pwd)
while getopts "hmg" opt; do
case "$opt" in
h)
showHelp
exit 0
;;
m) reportText=$2
parseRepos
saveReport
;;
g) reportText=""
parseRepos
saveReport
;;
esac
done
shift $((OPTIND-1))
}
main "$@"