bugzilla: add xmlrpcemail submission for Bugzilla 3.6 email interface
authorJim Hague <jim.hague@acm.org>
Thu, 01 Mar 2012 14:50:31 +0000
changeset 16224 d52a6b542db1
parent 16223 ac4fd3238ead
child 16227 7855c522a9cb
bugzilla: add xmlrpcemail submission for Bugzilla 3.6 email interface Some of the formatting details required for bug submission via email changed between Bugzilla 3.4 and 3.6. Bugzilla 3.4 requires lines of the form '@fieldname = value', while 3.6 wants '@fieldname value'. Also the field @bug_id in 3.4 becomes @id in 3.6. Bugzilla up to and including 4.0 also recognises the 3.4 format. To save surprises in the future, check the Bugzilla version and use the 3.6 format from all major versions >= 4. At some point we will drop support for Bugzilla prior to 3.6 and support the new format only.
hgext/bugzilla.py
--- a/hgext/bugzilla.py	Thu Mar 01 15:27:24 2012 +0000
+++ b/hgext/bugzilla.py	Thu Mar 01 14:50:31 2012 +0000
@@ -612,6 +612,9 @@
                                             'FIXED')
 
         self.bzproxy = xmlrpclib.ServerProxy(bzweb, self.transport(bzweb))
+        ver = self.bzproxy.Bugzilla.version()['version'].split('.')
+        self.bzvermajor = int(ver[0])
+        self.bzverminor = int(ver[1])
         self.bzproxy.User.login(dict(login=user, password=passwd))
 
     def transport(self, uri):
@@ -673,6 +676,13 @@
     But bugs can be marked fixed via email from 3.4 onwards.
     """
 
+    # The email interface changes subtly between 3.4 and 3.6. In 3.4,
+    # in-email fields are specified as '@<fieldname> = <value>'. In
+    # 3.6 this becomes '@<fieldname> <value>'. And fieldname @bug_id
+    # in 3.4 becomes @id in 3.6. 3.6 and 4.0 both maintain backwards
+    # compatibility, but rather than rely on this use the new format for
+    # 4.0 onwards.
+
     def __init__(self, ui):
         bzxmlrpc.__init__(self, ui)
 
@@ -681,6 +691,14 @@
             raise util.Abort(_("configuration 'bzemail' missing"))
         mail.validateconfig(self.ui)
 
+    def makecommandline(self, fieldname, value):
+        if self.bzvermajor >= 4:
+            return "@%s %s" % (fieldname, str(value))
+        else:
+            if fieldname == "id":
+                fieldname = "bug_id"
+            return "@%s = %s" % (fieldname, str(value))
+
     def send_bug_modify_email(self, bugid, commands, comment, committer):
         '''send modification message to Bugzilla bug via email.
 
@@ -701,8 +719,9 @@
                 raise util.Abort(_("default bugzilla user %s email not found") %
                                  user)
         user = matches['users'][0]['email']
+        commands.append(self.makecommandline("id", bugid))
 
-        text = "\n".join(commands) + "\n@bug_id = %d\n\n" % bugid + comment
+        text = "\n".join(commands) + "\n\n" + comment
 
         _charsets = mail._charsets(self.ui)
         user = mail.addressencode(self.ui, user, _charsets)