From 4c459c3a724ba6951352921ac2b5fb1ebdb5a2c3 Mon Sep 17 00:00:00 2001 From: Grant Bowman Date: Thu, 19 Aug 2004 05:29:56 +0000 Subject: [PATCH] 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. --- plugins/Bugzilla.py | 45 ++++++++++++++++++++++++++++++++++++++++++- test/test_Bugzilla.py | 9 +++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/plugins/Bugzilla.py b/plugins/Bugzilla.py index 87d15b405..71305dca7 100644 --- a/plugins/Bugzilla.py +++ b/plugins/Bugzilla.py @@ -93,6 +93,9 @@ conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'replyNoBugzilla', 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 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): List = ircutils.IrcSet @@ -115,7 +118,7 @@ def registerBugzilla(name, url='', description=''): class Bugzilla(callbacks.PrivmsgCommandAndRegexp): """Show a link to a bug report with a brief description""" threaded = True - regexps = ['bzSnarfer'] + regexps = ['bzSnarfer', 'bugzSnarf'] def __init__(self): callbacks.PrivmsgCommandAndRegexp.__init__(self) @@ -203,6 +206,46 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp): else: irc.reply('I have no defined bugzillae.') + def bugzSnarf(self, irc, msg, match): + r"""\s*bug\s*(?:id|ids|#)?\s+(?:id|ids|#)?(?P\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): r"(http://\S+)/show_bug.cgi\?id=([0-9]+)" if not self.registryValue('bugSnarfer', msg.args[0]): diff --git a/test/test_Bugzilla.py b/test/test_Bugzilla.py index 220244b2a..3ddb24794 100644 --- a/test/test_Bugzilla.py +++ b/test/test_Bugzilla.py @@ -58,5 +58,14 @@ if network: self.assertNotError( '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: