Bug 848222 - Use treestatus for SeaMonkey tree closures r=ted
authorJustin Wood <Callek@gmail.com>
Wed, 06 Mar 2013 12:35:48 -0500
changeset 157 93dc9c506add2f0c48e55054409ea18f0d688b78
parent 156 d7d2b8ffdc42c6c9a95970258f720ee764cad300
child 158 7bedd4ed8acf538743128ddb66e6089ef3b70d6c
push id86
push userCallek@gmail.com
push dateWed, 06 Mar 2013 17:36:31 +0000
reviewersted
bugs848222
Bug 848222 - Use treestatus for SeaMonkey tree closures r=ted
mozhghooks/treeclosure_comm_central.py
runtests.py
--- a/mozhghooks/treeclosure_comm_central.py
+++ b/mozhghooks/treeclosure_comm_central.py
@@ -1,11 +1,11 @@
 #!/usr/bin/env python
 
-# Copyright (C) 2012 Mozilla Foundation
+# Copyright (C) 2013 Mozilla Foundation
 #
 # 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
@@ -22,90 +22,22 @@ import re
 import json
 
 # Array of which directories SeaMonkey exclusively controls in comm-central
 seamonkeyOwns = [
   'suite'
 ]
 # Everything else is assumed to be controlled by Thunderbird.
 
-# SeaMonkey tinderbox trees
-seamonkeyTrees = {
-  'comm-central': 'http://tinderbox.mozilla.org/SeaMonkey/status.html',
-  'comm-aurora' : 'http://tinderbox.mozilla.org/SeaMonkey-Aurora/status.html',
-  'comm-beta'   : 'http://tinderbox.mozilla.org/SeaMonkey-Beta/status.html',
-  'comm-release': 'http://tinderbox.mozilla.org/SeaMonkey-Release/status.html',
-  'comm-esr10'  : None,
-  'comm-esr17'  : None,
-  # Point at Mirmar as SeaMonkey doesn't use this
-  'comm-miramar': None,
-  'comm-2.0'    : 'http://tinderbox.mozilla.org/SeaMonkey2.1/status.html',
-  'comm-1.9.1'  : 'http://tinderbox.mozilla.org/SeaMonkey2.0/status.html',
-  # Point at Thunderbird as SeaMonkey doesn't use this.
-  'comm-1.9.2'  : None,
-}
-
 magicwords = "CLOSED TREE"
 
 treestatus_base_url = "https://treestatus.mozilla.org"
 
 # This function actually does the checking to see if a tree is closed or set
 # to approval required.
-def checkTreeState(repo, repoName, treeName, treeUrl):
-    if not treeUrl:
-        # Fail open for trees that we don't have a url for.
-        return 0
-
-    # Get the tree state from tinderbox
-    try:
-        u = urlopen(treeUrl)
-    except IOError, e:
-        # If tinderbox is down, allow pushes
-        print "Tinderbox may be down, allowing your push, but you'd better check!"
-        return 0
-
-    text = ''.join(u.readlines()).strip()
-
-    if re.compile('<span id="tree-?status".*CLOSED.*<span id="extended-status">').search(text) :
-        # The tree is closed
-
-        # Tell the pusher
-        print "Tree %s is CLOSED! (%s, %s)" % (treeName, repoName, treeUrl)
-        print repo.changectx('tip').description()
-
-        # Block the push if no 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
-
-        # Otherwise let them push
-        print "But you included the magic words.  Hope you had permission!"
-        return 0
-
-    elif re.compile('<span id="tree-?status".*APPROVAL REQUIRED.*<span id="extended-status">').search(text) :
-        # The tree needs approval
-
-        # If they've specified an approval or are backing out, let them push
-        dlower = repo.changectx('tip').description().lower()
-        if re.search('a\S*=', dlower) or dlower.startswith('back') or dlower.startswith('revert'):
-            return 0
-
-        # Otherwise tell them about the rule
-        print "Pushing to an APPROVAL REQUIRED tree requires your top changeset comment to include: a=... (or, more accurately, a\\S*=...)"
-
-        # And block the push
-        return 1
-
-    elif not re.compile('<span id="tree-?status".*<span id="extended-status">').search(text):
-        print "The extended status span must be on the same line as the treestatus."
-        return 1
-
-    # By default the tree is open
-    return 0
-
 def checkJsonTreeState(repo, repoName, appName):
     name = os.path.basename(repo.root)
     url = "%s/%s-%s?format=json" % (treestatus_base_url, name, appName)
     try:
         u = urlopen(url)
         data = json.load(u)
 
         if data['status'] == 'closed':
@@ -170,31 +102,22 @@ def hook(ui, repo, node, **kwargs):
                 if isOwned(changedFile, seamonkeyOwns):
                     apps['seamonkey'] = True
                 else:
                     apps['thunderbird'] = True
 
         repoName = os.path.basename(repo.root)
         status = 0
 
-        # This can be replaced by "for app in apps:" once all apps have switched.
-        for app in ['thunderbird']:
+        for app in apps:
             if apps[app]:
                 status = checkJsonTreeState(repo, repoName, app)
                 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 and SeaMonkey... allowing push, but you should report this!" % (repoName)
-            else:
-                status = checkTreeState(repo, repoName, 'SeaMonkey', seamonkeyTrees[repoName])
-                if status == 1:
-                    return 1
-
         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
--- a/runtests.py
+++ b/runtests.py
@@ -387,23 +387,18 @@ class TestTreeCommCentralClosureHook(Clo
     shutil.rmtree(self.clonedir)
     ClosureHookTestHelpers.tearDown(self)
 
   def actualTestCCOpen(self, treeName, fileInfo):
     """Pushing to an OPEN CC tree should succeed."""
     # If this tests attempts to pull something that isn't treeName, then the
     # re-director should fail for us. Hence we know that the hook is only
     # pulling the predefined tree and nothing else.
-    if "Thunderbird" in treeName:
-        self.redirect("https://treestatus.mozilla.org/comm-central-" + treeName.lower() + "?format=json",
-                      '{"status": "open", "reason": null}')
-    else:
-        self.redirect("http://tinderbox.mozilla.org/" + treeName + "/status.html",
-                      '<span id="tree-status">OPEN</span><span id="extended-status">')
-
+    self.redirect("https://treestatus.mozilla.org/comm-central-" + treeName.lower() + "?format=json",
+                  '{"status": "open", "reason": null}')
 
     # pushing something should now succeed
     u = self.ui
 
     fileName = fileInfo.pop()
     fileLoc = self.clonedir
     for dir in fileInfo:
       fileLoc = join(fileLoc, dir)
@@ -428,22 +423,18 @@ class TestTreeCommCentralClosureHook(Clo
     # Calendar is now built alongside Thunderbird
     self.actualTestCCOpen("Thunderbird", ["calendar", "app", "test"])
 
   def actualTestCCClosed(self, treeName, fileInfo):
     """Pushing to a CLOSED CC tree should fail."""
     # If this tests attempts to pull something that isn't treeName, then the
     # re-director should fail for us. Hence we know that the hook is only
     # pulling the predefined tree and nothing else.
-    if "Thunderbird" in treeName:
-        self.redirect("https://treestatus.mozilla.org/comm-central-" + treeName.lower() + "?format=json",
-                      '{"status": "closed", "reason": null}')
-    else:
-        self.redirect("http://tinderbox.mozilla.org/" + treeName + "/status.html",
-                      '<span id="tree-status">CLOSED</span><span id="extended-status">')
+    self.redirect("https://treestatus.mozilla.org/comm-central-" + treeName.lower() + "?format=json",
+                  '{"status": "closed", "reason": null}')
 
     # pushing something should now fail
     u = self.ui
 
     fileName = fileInfo.pop()
     fileLoc = self.clonedir
     for dir in fileInfo:
       fileLoc = join(fileLoc, dir)