Move bug parsing into own module
authorGregory Szorc <gps@mozilla.com>
Thu, 07 Nov 2013 16:04:01 -0800
changeset 54 825f8368425de6b04fd30f7875168f0fe4bdc19e
parent 53 fa45c8eeb4ecad836cd9e39f8fe4e65805944ca3
child 55 125edeefc88c14c8da54fd7fd3948825a0002bc7
push id37
push usergszorc@mozilla.com
push dateFri, 08 Nov 2013 00:27:37 +0000
Move bug parsing into own module
__init__.py
mozautomation/commitparser.py
--- a/__init__.py
+++ b/__init__.py
@@ -181,16 +181,18 @@ from mercurial import (
     hg,
     util,
 )
 
 from mozautomation.changetracker import (
     ChangeTracker,
 )
 
+from mozautomation.commitparser import parse_bugs
+
 from mozautomation.repository import (
     MercurialRepository,
     RELEASE_TREES,
     REPOS,
     resolve_trees_to_official,
     resolve_trees_to_uris,
     resolve_uri_to_tree,
     tbpl_url,
@@ -659,17 +661,17 @@ def reposetup(ui, repo):
 
                 if tree:
                     self._update_remote_refs(remote, tree)
                     self.changetracker.load_pushlog(tree)
 
                 # Sync bug info.
                 for rev in self.changelog.revs(old_rev + 1):
                     ctx = self[rev]
-                    bugs = self._bugs_in_description(ctx.description())
+                    bugs = parse_bugs(ctx.description())
                     if bugs:
                         self.changetracker.associate_bugs_with_changeset(bugs,
                             ctx.node())
 
             finally:
                 lock.release()
 
             return res
@@ -798,39 +800,23 @@ def reposetup(ui, repo):
         def reset_bug_database(self):
             self.changetracker.wipe_bugs()
             self.sync_bug_database()
 
         def sync_bug_database(self):
             for rev in self:
                 ui.progress('changeset', rev, total=len(self))
                 ctx = self[rev]
-                bugs = self._bugs_in_description(ctx.description())
+                bugs = parse_bugs(ctx.description())
                 if bugs:
                     self.changetracker.associate_bugs_with_changeset(bugs,
                         ctx.node())
 
             ui.progress('changeset', None)
 
-        BUG_RE = re.compile(r'''# bug followed by any sequence of numbers, or
-                                # a standalone sequence of numbers
-                             (
-                               (?:
-                                 bug |
-                                 b= |
-                                 # a sequence of 5+ numbers preceded by whitespace
-                                 (?=\b\#?\d{5,}) |
-                                 # numbers at the very beginning
-                                 ^(?=\d)
-                               )
-                               (?:\s*\#?)(\d+)
-                             )''', re.I | re.X)
-
-        def _bugs_in_description(self, desc):
-            return [int(m[1]) for m in self.BUG_RE.findall(desc)]
 
     repo.__class__ = remotestrackingrepo
     headless = ui.configbool('mozext', 'headless')
     if not ui.config('mozext', 'ircnick') and not headless:
         raise util.Abort(_('Set "[mozext] ircnick" in your hgrc to your '
             'Mozilla IRC nickname to enable additional functionality.'))
 
     if not ui.configbool('mozext', 'noautocritic'):
new file mode 100644
--- /dev/null
+++ b/mozautomation/commitparser.py
@@ -0,0 +1,25 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# This module contains utilities for parsing commit messages.
+
+import re
+
+BUG_RE = re.compile(
+    r'''# bug followed by any sequence of numbers, or
+        # a standalone sequence of numbers
+         (
+           (?:
+             bug |
+             b= |
+             # a sequence of 5+ numbers preceded by whitespace
+             (?=\b\#?\d{5,}) |
+             # numbers at the very beginning
+             ^(?=\d)
+           )
+           (?:\s*\#?)(\d+)
+         )''', re.I | re.X)
+
+def parse_bugs(s):
+    return [int(m[1]) for m in BUG_RE.findall(s)]