Add support for Bugzilla 3.0 series to bugzilla hook.
authorJim Hague <jim.hague@acm.org>
Fri, 29 Aug 2008 20:36:55 +0100
changeset 7019 6b1ece890f9a
parent 7018 0b72836b0384
child 7020 5e9965407d53
Add support for Bugzilla 3.0 series to bugzilla hook. The only difference is 'fieldid' in table 'fielddefs' got renamed to 'id' for 3.0.
hgext/bugzilla.py
--- a/hgext/bugzilla.py	Wed Sep 10 13:52:33 2008 +0200
+++ b/hgext/bugzilla.py	Fri Aug 29 20:36:55 2008 +0100
@@ -80,11 +80,7 @@
         self.conn = MySQLdb.connect(host=host, user=user, passwd=passwd,
                                     db=db, connect_timeout=timeout)
         self.cursor = self.conn.cursor()
-        self.run('select fieldid from fielddefs where name = "longdesc"')
-        ids = self.cursor.fetchall()
-        if len(ids) != 1:
-            raise util.Abort(_('unknown database schema'))
-        self.longdesc_id = ids[0][0]
+        self.longdesc_id = self.get_longdesc_id()
         self.user_ids = {}
 
     def run(self, *args, **kwargs):
@@ -96,6 +92,14 @@
             self.ui.note(_('failed query: %s %s\n') % (args, kwargs))
             raise
 
+    def get_longdesc_id(self):
+        '''get identity of longdesc field'''
+        self.run('select fieldid from fielddefs where name = "longdesc"')
+        ids = self.cursor.fetchall()
+        if len(ids) != 1:
+            raise util.Abort(_('unknown database schema'))
+        return ids[0][0]
+
     def filter_real_bug_ids(self, ids):
         '''filter not-existing bug ids from list.'''
         self.run('select bug_id from bugs where bug_id in %s' % buglist(ids))
@@ -182,11 +186,26 @@
                     values (%s, %s, %s, %s)''',
                  (bugid, userid, now, self.longdesc_id))
 
+class bugzilla_3_0(bugzilla_2_16):
+    '''support for bugzilla 3.0 series.'''
+
+    def __init__(self, ui):
+        bugzilla_2_16.__init__(self, ui)
+
+    def get_longdesc_id(self):
+        '''get identity of longdesc field'''
+        self.run('select id from fielddefs where name = "longdesc"')
+        ids = self.cursor.fetchall()
+        if len(ids) != 1:
+            raise util.Abort(_('unknown database schema'))
+        return ids[0][0]
+
 class bugzilla(object):
     # supported versions of bugzilla. different versions have
     # different schemas.
     _versions = {
         '2.16': bugzilla_2_16,
+        '3.0':  bugzilla_3_0
         }
 
     _default_bug_re = (r'bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*'