[sysadmin-bin: 12/168] Add notification of "CIA" to the standard GNOME post-receive



commit 4d2da66466d958d18549ca1644f55eb4b8e1ccd6
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Fri Feb 6 18:59:06 2009 -0500

    Add notification of "CIA" to the standard GNOME post-receive
    
    When we get a branch update, find what commits are new to the repository
    and send notifications about them to the CIA system via ciabot.pl.

 gnome-post-receive      |    5 +++--
 post-receive-notify-cia |   45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/gnome-post-receive b/gnome-post-receive
index 5d4f371..55c3507 100755
--- a/gnome-post-receive
+++ b/gnome-post-receive
@@ -22,5 +22,6 @@ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
 GIT_CONFIG="${GIT_DIR}/config"
 export GIT_CONFIG
 
-tee >($BINDIR/log-push) \
-    | $BINDIR/post-receive-email
+tee >($BINDIR/log-push 1>&2) \
+    >($BINDIR/post-receive-notify-cia 1>&2) \
+    | $BINDIR/post-receive-email 1>&2
diff --git a/post-receive-notify-cia b/post-receive-notify-cia
new file mode 100755
index 0000000..7c4362f
--- /dev/null
+++ b/post-receive-notify-cia
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# In a post-receive hook, find out what commits are new (not in the
+# repository before) and notify the CIA system (IRC bots, etc) about it.
+
+BINDIR=$(cd $(dirname $0) && pwd)
+echo $BINDIR
+
+# Adapted from:
+#  http://kitenet.net/~joey/blog/entry/lazyweb:_git_cia_hooks/
+while read oldrev newrev refname; do
+    # Only pay attention to branch updates
+    if ! expr "$refname" : "refs/heads/" > /dev/null 2>& 1; then
+	continue
+    fi
+
+    # If the new revision is the null revision, it's a branch delete
+    if expr "$newrev" : '0\+$' > /dev/null 2>&1 ; then
+	continue
+    fi
+
+    # If the old revision is the null revision, it's a branch creation
+    if expr "$oldrev" : '0\+$' > /dev/null 2>&1 ; then
+	range="$newrev"
+    else
+	range="$oldrev..$newrev"
+    fi
+
+    branchname=${refname#refs/heads/}
+    [ "$branchname" = "master" ] && branchname=
+
+    # Take all the branches in the repo, as "^/ref/heads/branchname", other than the
+    # branch we are actualy committing to, and exclude commits already on those
+    # branches from the list of commits between $oldrev and $newrev.
+    #
+    # Note that if a commit is pushed to two branches at once, it won't get notified
+    # on either. That's bad, but probably better than repeating notifications
+    # on a merge of public branches.
+
+    for merged in $(git rev-parse --symbolic-full-name --not --branches | \
+                    egrep -v "^\^$refname$" | \
+		    git rev-list --reverse --stdin "$range"); do
+        $BINDIR/ciabot.pl $merged $branchname 1>&2
+    done
+done



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]