Bugzilla.py enhancement to allow snarfing "bug ###".

new config variable: supybot.plugins.Bugzilla.snarfTarget
Uses existing supybot.plugins.Bugzilla.bugSnarfer boolean for activation.
Includes update to test_Bugzilla.py.

Developed by Mike Taylor and I.
This commit is contained in:
Grant Bowman 2004-08-19 05:29:56 +00:00
parent f058b7ee7e
commit 4c459c3a72
2 changed files with 53 additions and 1 deletions

View File

@ -93,6 +93,9 @@ conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'replyNoBugzilla',
registry.String('I don\'t have a bugzilla %r.', """Determines the phrase registry.String('I don\'t have a bugzilla %r.', """Determines the phrase
to use when notifying the user that there is no information about that to use when notifying the user that there is no information about that
bugzilla site.""")) bugzilla site."""))
conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'snarfTarget',
registry.String('', """Determines the bugzilla site to query when the
snarf command is triggered"""))
class Bugzillae(registry.SpaceSeparatedListOfStrings): class Bugzillae(registry.SpaceSeparatedListOfStrings):
List = ircutils.IrcSet List = ircutils.IrcSet
@ -115,7 +118,7 @@ def registerBugzilla(name, url='', description=''):
class Bugzilla(callbacks.PrivmsgCommandAndRegexp): class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
"""Show a link to a bug report with a brief description""" """Show a link to a bug report with a brief description"""
threaded = True threaded = True
regexps = ['bzSnarfer'] regexps = ['bzSnarfer', 'bugzSnarf']
def __init__(self): def __init__(self):
callbacks.PrivmsgCommandAndRegexp.__init__(self) callbacks.PrivmsgCommandAndRegexp.__init__(self)
@ -203,6 +206,46 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
else: else:
irc.reply('I have no defined bugzillae.') irc.reply('I have no defined bugzillae.')
def bugzSnarf(self, irc, msg, match):
r"""\s*bug\s*(?:id|ids|#)?\s+(?:id|ids|#)?(?P<bug>\d+)"""
snarfTarget = self.registryValue('snarfTarget')
bugid = match.group('bug')
name = self.shorthand[snarfTarget]
try:
(url, description) = self.db[name]
except KeyError:
s = self.registryValue('replyNoBugzilla', name)
irc.error(s % name)
return
if not self.registryValue('bugSnarfer', name):
return
queryurl = '%s/xml.cgi?id=%s' % (url, bugid)
bold = self.registryValue('bold', name)
try:
summary = self._get_short_bug_summary(queryurl,description,bugid)
except BugzillaError, e:
irc.error(str(e))
return
except IOError, e:
s = '%s. Try yourself: %s' % (e, queryurl)
irc.error(s)
report = {}
report['id'] = bugid
report['url'] = str('%s/show_bug.cgi?id=%s' % (url, bugid))
report['title'] = str(summary['title'])
report['summary'] = str(self._mk_summary_string(summary, bold))
report['product'] = str(summary['product'])
s = '%(product)s bug #%(id)s: %(title)s %(summary)s' % report
irc.reply(s, prefixName=False)
def bzSnarfer(self, irc, msg, match): def bzSnarfer(self, irc, msg, match):
r"(http://\S+)/show_bug.cgi\?id=([0-9]+)" r"(http://\S+)/show_bug.cgi\?id=([0-9]+)"
if not self.registryValue('bugSnarfer', msg.args[0]): if not self.registryValue('bugSnarfer', msg.args[0]):

View File

@ -58,5 +58,14 @@ if network:
self.assertNotError( self.assertNotError(
'http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5') 'http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5')
def testConfigBugSnarfer(self):
self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc')
conf.supybot.plugins.bugzilla.bugSnarfer.setValue(False)
self.assertNoResponse(
'bug 5')
conf.supybot.plugins.bugzilla.bugSnarfer.setValue(True)
self.assertNotError(
'bug 5')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: