[PATCH] bugzilla: support sendbugmail.pl

Jim Hague jim.hague at acm.org
Wed Oct 29 15:55:20 UTC 2008


# HG changeset patch
# User Jim Hague <jim.hague at acm.org>
# Date 1225294377 0
# Node ID 0637381ee11c1701f63c49ff2c256d9e071d48a7
# Parent  76634cb7fe7bc5c89fad8d15a878df1b239655be
Bugzilla 2.18 and later use sendbugmail.pl, which requires committer name.

During 2.17, Bugzilla ditched the old 'processmail' script. With 2.18
contrib/sendbugmail.pl arrived in its place.

For notification emails to work properly, sendbugmail.pl requires as
its second parameter the Bugzilla user who made the commit. Otherwise
the user will not be recognised as the committer, and will receive
notification emails about the commit regardless of their preference
about being notified on their own commits.

diff --git a/hgext/bugzilla.py b/hgext/bugzilla.py
--- a/hgext/bugzilla.py
+++ b/hgext/bugzilla.py
@@ -118,7 +118,7 @@
             unknown.pop(id, None)
         return util.sort(unknown.keys())
 
-    def notify(self, ids):
+    def notify(self, ids, ctx):
         '''tell bugzilla to send mail.'''
 
         self.ui.status(_('telling bugzilla to send mail:\n'))
@@ -161,9 +161,10 @@
                 return bzuser
         return user
 
-    def add_comment(self, bugid, text, committer):
-        '''add comment to bug. try adding comment as committer of
-        changeset, otherwise as default bugzilla user.'''
+    def get_bugzilla_user(self, committer):
+        '''see if committer is a registered bugzilla user. Return
+        bugzilla username and userid if so. If not return default
+        bugzilla username and userid.'''
         user = self.map_committer(committer)
         try:
             userid = self.get_user_id(user)
@@ -174,9 +175,16 @@
                     raise util.Abort(_('cannot find bugzilla user id for %s') %
                                      user)
                 userid = self.get_user_id(defaultuser)
+                user = defaultuser
             except KeyError:
                 raise util.Abort(_('cannot find bugzilla user id for %s or %s') %
                                  (user, defaultuser))
+        return (user, userid)
+
+    def add_comment(self, bugid, text, committer):
+        '''add comment to bug. try adding comment as committer of
+        changeset, otherwise as default bugzilla user.'''
+        (user, userid) = self.get_bugzilla_user(committer)
         now = time.strftime('%Y-%m-%d %H:%M:%S')
         self.run('''insert into longdescs
                     (bug_id, who, bug_when, thetext)
@@ -186,11 +194,38 @@
                     values (%s, %s, %s, %s)''',
                  (bugid, userid, now, self.longdesc_id))
 
-class bugzilla_3_0(bugzilla_2_16):
+class bugzilla_2_18(bugzilla_2_16):
+    '''support for bugzilla 2.18 series. contrib/sendbugmail.pl
+    replaces processmail and requires username of committer.'''
+
+    def __init__(self, ui):
+        bugzilla_2_16.__init__(self, ui)
+
+    def notify(self, ids, ctx):
+        '''tell bugzilla to send mail. Supply email of committer of change
+        if they are a registered user, otherwise use default bugzilla user.'''
+
+        self.ui.status(_('telling bugzilla to send mail:\n'))
+        (user, userid) = self.get_bugzilla_user(util.email(ctx.user()))
+        for id in ids:
+            self.ui.status(_('  bug %s\n') % id)
+            cmd = self.ui.config('bugzilla', 'notify',
+                               'cd /var/www/html/bugzilla && '
+                               'contrib/sendbugmail.pl %s %s') % (id, user)
+            fp = util.popen('(%s) 2>&1' % cmd)
+            out = fp.read()
+            ret = fp.close()
+            if ret:
+                self.ui.warn(out)
+                raise util.Abort(_('bugzilla notify command %s') %
+                                 util.explain_exit(ret)[0])
+        self.ui.status(_('done\n'))
+
+class bugzilla_3_0(bugzilla_2_18):
     '''support for bugzilla 3.0 series.'''
 
     def __init__(self, ui):
-        bugzilla_2_16.__init__(self, ui)
+        bugzilla_2_18.__init__(self, ui)
 
     def get_longdesc_id(self):
         '''get identity of longdesc field'''
@@ -202,9 +237,10 @@
 
 class bugzilla(object):
     # supported versions of bugzilla. different versions have
-    # different schemas.
+    # different schemas or tools.
     _versions = {
         '2.16': bugzilla_2_16,
+        '2.18': bugzilla_2_18,
         '3.0':  bugzilla_3_0
         }
 
@@ -320,7 +356,7 @@
         if ids:
             for id in ids:
                 bz.update(id, ctx)
-            bz.notify(ids)
+            bz.notify(ids, ctx)
     except MySQLdb.MySQLError, err:
         raise util.Abort(_('database error: %s') % err[1])
 


More information about the Mercurial-devel mailing list