Mercurial > hg
comparison hgext/bugzilla.py @ 7019:6b1ece890f9a
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.
author | Jim Hague <jim.hague@acm.org> |
---|---|
date | Fri, 29 Aug 2008 20:36:55 +0100 |
parents | f67d1468ac50 |
children | 810ca383da9c |
comparison
equal
deleted
inserted
replaced
7018:0b72836b0384 | 7019:6b1ece890f9a |
---|---|
78 self.ui.note(_('connecting to %s:%s as %s, password %s\n') % | 78 self.ui.note(_('connecting to %s:%s as %s, password %s\n') % |
79 (host, db, user, '*' * len(passwd))) | 79 (host, db, user, '*' * len(passwd))) |
80 self.conn = MySQLdb.connect(host=host, user=user, passwd=passwd, | 80 self.conn = MySQLdb.connect(host=host, user=user, passwd=passwd, |
81 db=db, connect_timeout=timeout) | 81 db=db, connect_timeout=timeout) |
82 self.cursor = self.conn.cursor() | 82 self.cursor = self.conn.cursor() |
83 self.run('select fieldid from fielddefs where name = "longdesc"') | 83 self.longdesc_id = self.get_longdesc_id() |
84 ids = self.cursor.fetchall() | |
85 if len(ids) != 1: | |
86 raise util.Abort(_('unknown database schema')) | |
87 self.longdesc_id = ids[0][0] | |
88 self.user_ids = {} | 84 self.user_ids = {} |
89 | 85 |
90 def run(self, *args, **kwargs): | 86 def run(self, *args, **kwargs): |
91 '''run a query.''' | 87 '''run a query.''' |
92 self.ui.note(_('query: %s %s\n') % (args, kwargs)) | 88 self.ui.note(_('query: %s %s\n') % (args, kwargs)) |
93 try: | 89 try: |
94 self.cursor.execute(*args, **kwargs) | 90 self.cursor.execute(*args, **kwargs) |
95 except MySQLdb.MySQLError, err: | 91 except MySQLdb.MySQLError, err: |
96 self.ui.note(_('failed query: %s %s\n') % (args, kwargs)) | 92 self.ui.note(_('failed query: %s %s\n') % (args, kwargs)) |
97 raise | 93 raise |
94 | |
95 def get_longdesc_id(self): | |
96 '''get identity of longdesc field''' | |
97 self.run('select fieldid from fielddefs where name = "longdesc"') | |
98 ids = self.cursor.fetchall() | |
99 if len(ids) != 1: | |
100 raise util.Abort(_('unknown database schema')) | |
101 return ids[0][0] | |
98 | 102 |
99 def filter_real_bug_ids(self, ids): | 103 def filter_real_bug_ids(self, ids): |
100 '''filter not-existing bug ids from list.''' | 104 '''filter not-existing bug ids from list.''' |
101 self.run('select bug_id from bugs where bug_id in %s' % buglist(ids)) | 105 self.run('select bug_id from bugs where bug_id in %s' % buglist(ids)) |
102 return util.sort([c[0] for c in self.cursor.fetchall()]) | 106 return util.sort([c[0] for c in self.cursor.fetchall()]) |
180 (bugid, userid, now, text)) | 184 (bugid, userid, now, text)) |
181 self.run('''insert into bugs_activity (bug_id, who, bug_when, fieldid) | 185 self.run('''insert into bugs_activity (bug_id, who, bug_when, fieldid) |
182 values (%s, %s, %s, %s)''', | 186 values (%s, %s, %s, %s)''', |
183 (bugid, userid, now, self.longdesc_id)) | 187 (bugid, userid, now, self.longdesc_id)) |
184 | 188 |
189 class bugzilla_3_0(bugzilla_2_16): | |
190 '''support for bugzilla 3.0 series.''' | |
191 | |
192 def __init__(self, ui): | |
193 bugzilla_2_16.__init__(self, ui) | |
194 | |
195 def get_longdesc_id(self): | |
196 '''get identity of longdesc field''' | |
197 self.run('select id from fielddefs where name = "longdesc"') | |
198 ids = self.cursor.fetchall() | |
199 if len(ids) != 1: | |
200 raise util.Abort(_('unknown database schema')) | |
201 return ids[0][0] | |
202 | |
185 class bugzilla(object): | 203 class bugzilla(object): |
186 # supported versions of bugzilla. different versions have | 204 # supported versions of bugzilla. different versions have |
187 # different schemas. | 205 # different schemas. |
188 _versions = { | 206 _versions = { |
189 '2.16': bugzilla_2_16, | 207 '2.16': bugzilla_2_16, |
208 '3.0': bugzilla_3_0 | |
190 } | 209 } |
191 | 210 |
192 _default_bug_re = (r'bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*' | 211 _default_bug_re = (r'bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*' |
193 r'((?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)') | 212 r'((?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)') |
194 | 213 |