Add irker hook
authorNeil Muller <drnlmuller@gmail.com>
Mon, 9 Mar 2020 13:06:27 +0000 (15:06 +0200)
committerNeil Muller <drnlmuller@gmail.com>
Mon, 9 Mar 2020 13:06:27 +0000 (15:06 +0200)
irker [new file with mode: 0755]

diff --git a/irker b/irker
new file mode 100755 (executable)
index 0000000..ab0b10a
--- /dev/null
+++ b/irker
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+IRKERPATH=/home/irker/VE/bin/
+
+function help() {
+  echo "Required config settings:"
+  echo "  git config irker.channels 'channel1 channel2 ..'"
+  echo "  git config irker.project 'Project name'"
+  echo "  git config irker.server 'server'"
+  echo "  git config irker.server 'server'"
+}
+
+
+function notify_irker() {
+   old=$1
+   new=$2
+   refname=$3
+
+   if [ "x$old" = "x0000000000000000000000000000000000000000" ]; then
+      # We're pushing into an empty repo, so we need a different command
+      # to get the rev list
+      # This does the wrong thing if the parent of the branch isn't master
+      # but it is kind of correct most of the time
+      ${IRKERPATH}/irkerhook.py --refname=${refname} \
+           $(git rev-list $new --not master)
+   elif [ "x$new" = "x0000000000000000000000000000000000000000" ]; then
+      # We're deleting a branch - we need to do the right thing
+      # (whatever that is)
+      # This is not the right thing, but will do for now
+      repo=$(basename $PWD | sed 's/.git$//' )
+      for channel in $(git config --get irker.channels | sed "s/,/ /"); do
+         ${IRKERPATH}/irk $channel "$repo: Deleted branch $refname"
+      done
+   else
+      ${IRKERPATH}/irkerhook.py --refname=${refname} \
+           $(git rev-list --reverse ${old}..${new})
+   fi
+}
+
+channels=$(git config --get irker.channels)
+
+while read line; do
+  set -- $line
+  if [ -n "$channels" ]; then
+      notify_irker $*
+  fi
+  RET=$?
+done
+
+exit $RET