#!/bin/bash

#set -x
set -e
set -o pipefail

check() {
   if [ ! "$1" = "$(basename $(pwd))" ]; then
      ## git makes no new lines.
      echo ""
      echo "ERROR!" >&2
      echo "$1 is not $(basename $(pwd))" >&2
      echo "ERROR!" >&2
      exit 1
   fi
}

iterate() {
   for pkg in ./*; do
      if [ ! -d "$pkg" ]; then
         continue
      fi
      cd "$pkg"
      doit
      cd ..
   done
}

doit() {
   package="$(basename $(pwd))"
   #git log --pretty=oneline --abbrev-commit --author=adrelanos --since="01.08.2015" --until="31.08.2015" | sed "s,^,https://github.com/adrelanos/$package/commit/,"
   output="$(git --no-pager log --author=adrelanos --since="01.09.2016" --until="31.09.2016" --pretty="format:https://github.com/adrelanos/$package/commit/%h %s %b")"
   if [ ! "$output" = "" ]; then
      echo "$output"
      echo ""
   fi
}

## Whonix/Whonix
cd ..
cd ..
check "Whonix"
doit
#sleep 5

## Whonix/packages
cd "packages"
iterate "packages"
#sleep 5

## Qubes
cd ~/"Qubes"
iterate "Qubes"

#echo ""
