[sysadmin-bin: 77/168] Add a post-receive hook for sending out rebuild triggers



commit e31e0ea4af2b70dd669c679712989fefcd44b122
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Wed Apr 15 18:34:05 2009 -0400

    Add a post-receive hook for sending out rebuild triggers
    
    post-receive-notify-updates: Script that sends out mails on branch
     updates suitable for triggering automatic website updates.
    gnome-post-receive: Call post-receive-notify-updates

 gnome-post-receive          |    1 +
 post-receive-notify-updates |  115 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 0 deletions(-)
---
diff --git a/gnome-post-receive b/gnome-post-receive
index 379e9ad..1cc4be2 100755
--- a/gnome-post-receive
+++ b/gnome-post-receive
@@ -24,4 +24,5 @@ export GIT_CONFIG
 
 tee >($BINDIR/log-push 1>&2) \
     >($BINDIR/post-receive-notify-cia 1>&2) \
+    >($BINDIR/post-receive-notify-updates 1>&2) \
     | $BINDIR/gnome-post-receive-email 1>&2
diff --git a/post-receive-notify-updates b/post-receive-notify-updates
new file mode 100755
index 0000000..780fe40
--- /dev/null
+++ b/post-receive-notify-updates
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+#
+# post-receive-notify-updates
+#
+# Copyright (C) 2008  Owen Taylor
+# Copyright (C) 2009  Red Hat, Inc
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, If not, see
+# http://www.gnu.org/licenses/.
+#
+# About
+# =====
+# This script is used to send out notification mails on branch updates; these
+# notification mails are typically used to trigger automated rebuilds
+#
+
+import re
+import os
+import pwd
+import sys
+
+script_path = os.path.realpath(os.path.abspath(sys.argv[0]))
+script_dir = os.path.dirname(script_path)
+
+sys.path.insert(0, script_dir)
+
+from git import *
+from util import die, strip_string as s, start_email, end_email
+
+# These addresses always get notified
+ALL_MODULE_RECIPIENTS = [ "gnomeweb progress gnome org" ]
+
+BRANCH_RE = re.compile(r'^refs/heads/(.*)$')
+def get_branch_name(refname):
+    m = BRANCH_RE.match(refname)
+    if m:
+        return m.group(1)
+
+SPLIT_RE = re.compile("\s*,\s*")
+
+def main():
+    module_name = get_module_name()
+
+    try:
+        recipients_s = git.config("hooks.update-recipients", _quiet=True)
+    except CalledProcessError:
+        recipients_s = ""
+
+    recipients_s = recipients_s.strip()
+    if recipients_s == "":
+        recipients = []
+    else:
+        recipients = SPLIT_RE.split(recipients_s)
+
+    for recipient in ALL_MODULE_RECIPIENTS:
+        if not recipient in recipients:
+            recipients.append(recipient)
+
+    changes = []
+
+    if len(sys.argv) > 1:
+        # For testing purposes, allow passing in a ref update on the command line
+        if len(sys.argv) != 4:
+            die("Usage: post-receive-notify-updates OLDREV NEWREV REFNAME")
+        branch_name = get_branch_name(sys.argv[3])
+        if branch_name is not None:
+            changes.append((branch_name, sys.argv[1], sys.argv[2], sys.argv[3]))
+    else:
+        for line in sys.stdin:
+            items = line.strip().split()
+            if len(items) != 3:
+                die("Input line has unexpected number of items")
+            branch_name = get_branch_name(items[2])
+            if branch_name is not None:
+                changes.append((branch_name, items[0], items[1], items[2]))
+
+    if len(changes) == 0:
+        # Nothing to mail about
+        return
+
+    branches = [branch_name for branch_name, _, _, _ in changes]
+    subject = "GNOME_GIT " + module_name + " " + " ".join(branches)
+
+    out = start_email()
+
+    print >>out, s("""
+To: %(recipients)s
+From: nobody git gnome org
+Subject: %(subject)s
+""") % {
+            'recipients': ", ".join(recipients),
+            'subject': subject
+       }
+
+    # Trailing newline to signal the end of the header
+    print >>out
+
+    for _, oldrev, newrev, refname in changes:
+        print >>out, oldrev, newrev, refname
+
+    end_email()
+
+if __name__ == '__main__':
+    main()



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