hgext/bugzilla.py
changeset 10292 ea7a14ca118a
parent 10282 08a0f04b56bd
child 10481 3062af0ba177
equal deleted inserted replaced
10291:61c93743fae0 10292:ea7a14ca118a
   143 from mercurial.i18n import _
   143 from mercurial.i18n import _
   144 from mercurial.node import short
   144 from mercurial.node import short
   145 from mercurial import cmdutil, templater, util
   145 from mercurial import cmdutil, templater, util
   146 import re, time
   146 import re, time
   147 
   147 
   148 MySQLdb = None
   148 mysqldb = None
   149 
   149 
   150 def buglist(ids):
   150 def buglist(ids):
   151     return '(' + ','.join(map(str, ids)) + ')'
   151     return '(' + ','.join(map(str, ids)) + ')'
   152 
   152 
   153 class bugzilla_2_16(object):
   153 class bugzilla_2_16(object):
   163         usermap = self.ui.config('bugzilla', 'usermap')
   163         usermap = self.ui.config('bugzilla', 'usermap')
   164         if usermap:
   164         if usermap:
   165             self.ui.readconfig(usermap, sections=['usermap'])
   165             self.ui.readconfig(usermap, sections=['usermap'])
   166         self.ui.note(_('connecting to %s:%s as %s, password %s\n') %
   166         self.ui.note(_('connecting to %s:%s as %s, password %s\n') %
   167                      (host, db, user, '*' * len(passwd)))
   167                      (host, db, user, '*' * len(passwd)))
   168         self.conn = MySQLdb.connect(host=host, user=user, passwd=passwd,
   168         self.conn = mysqldb.connect(host=host, user=user, passwd=passwd,
   169                                     db=db, connect_timeout=timeout)
   169                                     db=db, connect_timeout=timeout)
   170         self.cursor = self.conn.cursor()
   170         self.cursor = self.conn.cursor()
   171         self.longdesc_id = self.get_longdesc_id()
   171         self.longdesc_id = self.get_longdesc_id()
   172         self.user_ids = {}
   172         self.user_ids = {}
   173         self.default_notify = "cd %(bzdir)s && ./processmail %(id)s %(user)s"
   173         self.default_notify = "cd %(bzdir)s && ./processmail %(id)s %(user)s"
   175     def run(self, *args, **kwargs):
   175     def run(self, *args, **kwargs):
   176         '''run a query.'''
   176         '''run a query.'''
   177         self.ui.note(_('query: %s %s\n') % (args, kwargs))
   177         self.ui.note(_('query: %s %s\n') % (args, kwargs))
   178         try:
   178         try:
   179             self.cursor.execute(*args, **kwargs)
   179             self.cursor.execute(*args, **kwargs)
   180         except MySQLdb.MySQLError:
   180         except mysqldb.MySQLError:
   181             self.ui.note(_('failed query: %s %s\n') % (args, kwargs))
   181             self.ui.note(_('failed query: %s %s\n') % (args, kwargs))
   182             raise
   182             raise
   183 
   183 
   184     def get_longdesc_id(self):
   184     def get_longdesc_id(self):
   185         '''get identity of longdesc field'''
   185         '''get identity of longdesc field'''
   417 def hook(ui, repo, hooktype, node=None, **kwargs):
   417 def hook(ui, repo, hooktype, node=None, **kwargs):
   418     '''add comment to bugzilla for each changeset that refers to a
   418     '''add comment to bugzilla for each changeset that refers to a
   419     bugzilla bug id. only add a comment once per bug, so same change
   419     bugzilla bug id. only add a comment once per bug, so same change
   420     seen multiple times does not fill bug with duplicate data.'''
   420     seen multiple times does not fill bug with duplicate data.'''
   421     try:
   421     try:
   422         import MySQLdb as mysql
   422         import mysqldb as mysql
   423         global MySQLdb
   423         global mysqldb
   424         MySQLdb = mysql
   424         mysqldb = mysql
   425     except ImportError, err:
   425     except ImportError, err:
   426         raise util.Abort(_('python mysql support not available: %s') % err)
   426         raise util.Abort(_('python mysql support not available: %s') % err)
   427 
   427 
   428     if node is None:
   428     if node is None:
   429         raise util.Abort(_('hook type %s does not pass a changeset id') %
   429         raise util.Abort(_('hook type %s does not pass a changeset id') %
   434         ids = bz.find_bug_ids(ctx)
   434         ids = bz.find_bug_ids(ctx)
   435         if ids:
   435         if ids:
   436             for id in ids:
   436             for id in ids:
   437                 bz.update(id, ctx)
   437                 bz.update(id, ctx)
   438             bz.notify(ids, util.email(ctx.user()))
   438             bz.notify(ids, util.email(ctx.user()))
   439     except MySQLdb.MySQLError, err:
   439     except mysqldb.MySQLError, err:
   440         raise util.Abort(_('database error: %s') % err[1])
   440         raise util.Abort(_('database error: %s') % err[1])
   441 
   441