Bug 530781 Investigate use of hg hooks for comm-*. Add initial version of hook file for comm-*. r=KaiRo,gozer
authorMark Banner <bugzilla@standard8.plus.com>
Fri, 15 Jan 2010 22:51:42 +0000
changeset 359111 3395039251530d9f1118de0137572d9f037514c5
parent 359110 94fca0d621346aa272811d72b79d872e99b11c94
child 359112 6b560ece0c3ac2eceda7c272467d8ccb2c24f4f1
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
reviewersKaiRo, gozer
bugs530781
Bug 530781 Investigate use of hg hooks for comm-*. Add initial version of hook file for comm-*. r=KaiRo,gozer
hghooks/mozhghooks/treeclosure_comm_central.py
new file mode 100644
--- /dev/null
+++ b/hghooks/mozhghooks/treeclosure_comm_central.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+from urllib import urlopen
+import os.path
+import re
+
+# Array of which directories Calendar exclusively controls in comm-central
+calendarOwns = [
+  'calendar',
+  'other-licenses/branding/sunbird'
+]
+
+# Array of which directories SeaMonkey exclusively controls in comm-central
+seamonkeyOwns = [
+  'suite'
+]
+# Everything else is assumed to be controlled by Thunderbird.
+
+
+# Thunderbird tinderbox trees
+thunderbirdTrees = {
+  'comm-central': 'http://tinderbox.mozilla.org/Thunderbird/',
+  'comm-1.9.1'  : 'http://tinderbox.mozilla.org/Thunderbird3.0/',
+  'comm-1.9.2'  : 'http://tinderbox.mozilla.org/Thunderbird3.1/'
+}
+# SeaMonkey tinderbox trees
+seamonkeyTrees = {
+  'comm-central': 'http://tinderbox.mozilla.org/SeaMonkey/',
+  'comm-1.9.1'  : 'http://tinderbox.mozilla.org/SeaMonkey2.0/',
+}
+# Calendar tinderbox trees
+calendarTrees = {
+  'comm-central': 'http://tinderbox.mozilla.org/Sunbird/',
+  'comm-1.9.1'  : 'http://tinderbox.mozilla.org/Calendar1.0/',
+}
+
+
+magicwords = "CLOSED TREE"
+
+# This function actually does the checking to see if a tree is closed or set
+# to approval required.
+def checkTreeState(repo, repoName, treeName, treeUrl):
+    u = urlopen(treeUrl)
+    text = ''.join(u.readlines()).strip()
+
+    if re.compile('<span id="tree-status".*CLOSED.*<span id="extended-status">').search(text) :
+        print "Tree %s is CLOSED! (%s, %s)" % (treeName, repoName, treeUrl)
+        print repo.changectx('tip').description()
+        # Block the push unless they know the magic words
+        if repo.changectx('tip').description().find(magicwords) == -1:
+            print "To push despite the closed tree, include \"%s\" in your push comment" % magicwords
+            return 1
+
+        print "But you included the magic words.  Hope you had permission!"
+        return 0
+
+
+def hook(ui, repo, node, **kwargs):
+    try:
+        # First find out which trees are affected
+        apps = { 'thunderbird' : False,
+                 'seamonkey' : False,
+                 'calendar' : False }
+
+        # all changesets from node to 'tip' inclusive are part of this push
+        rev = repo.changectx(node).rev()
+        tip = repo.changectx('tip').rev()
+        for i in range(rev, tip+1):
+            ctx = repo.changectx(i)
+            for changedFile in ctx.files():
+                if os.path.dirname(changedFile) in calendarOwns:
+                    apps['calendar'] = True
+                elif os.path.dirname(changedFile) in seamonkeyOwns:
+                    apps['seamonkey'] = True
+                else:
+                    apps['thunderbird'] = True
+
+        affectedTrees = []
+        repoName = os.path.basename(repo.root)
+        status = 0
+
+        if apps['thunderbird']:
+            if not thunderbirdTrees.has_key(repoName):
+                print "Unrecognized tree!  I don't know how to check closed status for %s." % name
+            else:
+                status = checkTreeState(repo, repoName, 'Thunderbird', thunderbirdTrees[repoName])
+                if status == 1:
+                    return 1
+
+        if apps['seamonkey']:
+            if not seamonkeyTrees.has_key(repoName):
+                print "Unrecognized tree!  I don't know how to check closed status for %s." % name
+            else:
+                status = checkTreeState(repo, repoName, 'SeaMonkey', seamonkeyTrees[repoName])
+                if status == 1:
+                    return 1
+
+        if apps['calendar']:
+            if not calendarTrees.has_key(repoName):
+                print "Unrecognized tree!  I don't know how to check closed status for %s." % name
+            else:
+                 status = checkTreeState(repo, repoName, 'Calendar', calendarTrees[repoName])
+
+        return status;
+        
+            
+    except IOError, (err):
+        # fail open, I guess. no sense making hg unavailable
+        # if the wiki is down
+        print "IOError: %s" % err
+        pass
+    return 0