Bugtracker: Drop loop off report handling.

This commit is contained in:
Krytarik Raido
2017-08-08 23:04:04 +02:00
parent 398247f0dd
commit 681895bfc7
2 changed files with 71 additions and 72 deletions

View File

@ -24,7 +24,7 @@ import supybot.world as world
from imp import reload from imp import reload
__version__ = "2.9.0" __version__ = "3.0.0"
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com") __author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com")
__contributors__ = { __contributors__ = {
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'], supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'],

View File

@ -319,8 +319,8 @@ class Bugtracker(callbacks.PluginRegexp):
return return
irc.error(str(e)) irc.error(str(e))
else: else:
for r in report: if report:
irc.reply(r) irc.reply(report)
def turlSnarfer(self, irc, msg, match): def turlSnarfer(self, irc, msg, match):
r"(https?://)?((bugs\.debian\.org|pad\.lv)/|\S+/(show_bug\.cgi\?id=|bugreport\.cgi\?bug=|view\.php\?id=|bug=|bugs/|\+bug/|ticket/|feature-requests/|patches/|todo/|issues/|pulls?/))(?P<bug>\d+)/?" r"(https?://)?((bugs\.debian\.org|pad\.lv)/|\S+/(show_bug\.cgi\?id=|bugreport\.cgi\?bug=|view\.php\?id=|bug=|bugs/|\+bug/|ticket/|feature-requests/|patches/|todo/|issues/|pulls?/))(?P<bug>\d+)/?"
@ -348,8 +348,8 @@ class Bugtracker(callbacks.PluginRegexp):
if self.registryValue('replyWhenNotFound'): if self.registryValue('replyWhenNotFound'):
irc.error("Could not find %s bug %s" % (tracker.description, match.group('bug'))) irc.error("Could not find %s bug %s" % (tracker.description, match.group('bug')))
else: else:
for r in report: if report:
irc.reply(r) irc.reply(report)
# Only useful to Launchpad developers # Only useful to Launchpad developers
def oopsSnarfer(self, irc, msg, match): def oopsSnarfer(self, irc, msg, match):
@ -423,76 +423,75 @@ class Bugtracker(callbacks.PluginRegexp):
elif '/ticket/' in snarfurl: elif '/ticket/' in snarfurl:
tracker = Trac().get_tracker(snarfurl) tracker = Trac().get_tracker(snarfurl)
else: else:
return None return
if tracker: if tracker:
self.db[tracker.name] = tracker self.db[tracker.name] = tracker
self.shorthand = utils.abbrev(list(self.db.keys())) self.shorthand = utils.abbrev(list(self.db.keys()))
return tracker return tracker
return None
def get_bug(self, channel, tracker, id, do_assignee, do_extinfo, do_url=True, do_tracker=True): def get_bug(self, channel, tracker, id, do_assignee, do_extinfo, do_url=True, do_tracker=True):
reports = []
message_max = 450 - len(channel)
if not self.is_ok(channel, tracker, id): if not self.is_ok(channel, tracker, id):
return [] return
for r in tracker.get_bug(id): bugdata = tracker.get_bug(id)
(bid, product, title, severity, status, assignee, url, extinfo, duplicate) = r if not bugdata:
return
if duplicate and not self.is_ok(channel, tracker, bid): (bid, product, title, severity, status, assignee, url, extinfo, duplicate) = bugdata
continue
bugtype = re.match(r'.*/(feature-)?(?P<type>request|patch|todo|issue|pull|ticket)(e?s)?/[0-9]+/?$', url) if duplicate and not self.is_ok(channel, tracker, bid):
if do_tracker and tracker.trackertype != 'github': return
if re.match(r'.*/(bugs|feature-requests|patches|todo|issues|pulls?|ticket)/?$', tracker.description):
report = '%s %d' % (tracker.description, bid) bugtype = re.match(r'.*/(feature-)?(?P<type>request|patch|todo|issue|pull|ticket)(e?s)?/[0-9]+/?$', url)
else: if do_tracker and tracker.trackertype != 'github':
if bugtype: if re.match(r'.*/(bugs|feature-requests|patches|todo|issues|pulls?|ticket)/?$', tracker.description):
report = '%s %s %d' % (tracker.description, bugtype.group('type'), bid) report = '%s %d' % (tracker.description, bid)
else:
report = '%s bug %d' % (tracker.description, bid)
else: else:
if bugtype: if bugtype:
report = '%s %d' % (bugtype.group('type').title(), bid) report = '%s %s %d' % (tracker.description, bugtype.group('type'), bid)
else: else:
report = 'Bug %d' % bid report = '%s bug %d' % (tracker.description, bid)
else:
if bugtype:
report = '%s %d' % (bugtype.group('type').title(), bid)
else:
report = 'Bug %d' % bid
if product: if product:
report += ' in %s' % product report += ' in %s' % product
report += ' "%s"' % title.replace('"', "'").strip() report += ' "%s"' % title.replace('"', "'").strip()
if do_extinfo and extinfo: if do_extinfo and extinfo:
report += ' (%s)' % ', '.join(extinfo) report += ' (%s)' % ', '.join(extinfo)
if do_assignee and assignee: if do_assignee and assignee:
report += ' (assigned: %s)' % assignee report += ' (assigned: %s)' % assignee
severity_status = [] severity_status = []
if severity: if severity:
severity_status.append(' '.join(word[0].upper() + word[1:].lower() for word in severity.split())) severity_status.append(' '.join(word[0].upper() + word[1:].lower() for word in severity.split()))
severity_status.append(' '.join(word[0].upper() + word[1:].lower() for word in status.split())) severity_status.append(' '.join(word[0].upper() + word[1:].lower() for word in status.split()))
report += ' [%s]' % ', '.join(severity_status) report += ' [%s]' % ', '.join(severity_status)
if duplicate: if duplicate:
report += ' [duplicate: %s]' % duplicate[0] report += ' [duplicate: %s]' % duplicate[0]
if do_url: if do_url:
report += ' %s' % url report += ' %s' % url
if len(report) > message_max: message_max = 450 - len(channel)
report_parts = report.split('"') if len(report) > message_max:
report_start = report_parts[0] report_parts = report.split('"')
report_end = report_parts[-1] report_start = report_parts[0]
report_title = '"'.join(report_parts[1:-1]) report_end = report_parts[-1]
title_max = message_max - len(report_start) - len(report_end) - 5 report_title = '"'.join(report_parts[1:-1])
report_title_cut = report_title[:title_max].rsplit(None, 1)[0] + '...' title_max = message_max - len(report_start) - len(report_end) - 5
report = '%s"%s"%s' % (report_start, report_title_cut, report_end) report_title_cut = report_title[:title_max].rsplit(None, 1)[0] + '...'
report = '%s"%s"%s' % (report_start, report_title_cut, report_end)
reports.append(report) return report
return reports
# Define all bugtrackers # Define all bugtrackers
class IBugtracker: class IBugtracker:
@ -531,7 +530,7 @@ class Bugzilla(IBugtracker):
# registerBugtracker(name, url, desc, 'bugzilla') # registerBugtracker(name, url, desc, 'bugzilla')
return Bugzilla(name, url, desc, 'bugzilla') return Bugzilla(name, url, desc, 'bugzilla')
except: except:
return None pass
def get_bug(self, id): def get_bug(self, id):
url = "%s/rest/bug/%d" % (self.url, id) url = "%s/rest/bug/%d" % (self.url, id)
@ -553,8 +552,8 @@ class Bugzilla(IBugtracker):
assignee = bug['assigned_to_detail']['name'] assignee = bug['assigned_to_detail']['name']
else: else:
assignee = '' assignee = ''
return [(id, bug['product'], bug['summary'], bug['severity'], status, assignee, return (id, bug['product'], bug['summary'], bug['severity'], status, assignee,
"%s/show_bug.cgi?id=%d" % (self.url, id), [], [])] "%s/show_bug.cgi?id=%d" % (self.url, id), [], [])
except Exception as e: except Exception as e:
raise BugtrackerError(self.errparse % (self.description, e, url)) raise BugtrackerError(self.errparse % (self.description, e, url))
@ -590,7 +589,7 @@ class Bugzilla(IBugtracker):
assignee = '' assignee = ''
except Exception as e: except Exception as e:
raise BugtrackerError(self.errparse % (self.description, e, url)) raise BugtrackerError(self.errparse % (self.description, e, url))
return [(id, product, title, severity, status, assignee, "%s/show_bug.cgi?id=%d" % (self.url, id), [], [])] return (id, product, title, severity, status, assignee, "%s/show_bug.cgi?id=%d" % (self.url, id), [], [])
class Launchpad(IBugtracker): class Launchpad(IBugtracker):
statuses = ("Unknown", "Invalid", "Opinion", "Won't Fix", "Fix Released", "Fix Committed", "New", statuses = ("Unknown", "Invalid", "Opinion", "Won't Fix", "Fix Released", "Fix Committed", "New",
@ -715,8 +714,8 @@ class Launchpad(IBugtracker):
raise BugNotFoundError raise BugNotFoundError
raise BugtrackerError(self.errget % (self.description, e, '%s/bugs/%d' % (self.url, id))) raise BugtrackerError(self.errget % (self.description, e, '%s/bugs/%d' % (self.url, id)))
return [(bugdata.id, taskdata.bug_target_display_name, bugdata.title, taskdata.importance, taskdata.status, return (bugdata.id, taskdata.bug_target_display_name, bugdata.title, taskdata.importance, taskdata.status,
assignee, "%s/bugs/%d" % (self.url, bugdata.id), extinfo, duplicate)] assignee, "%s/bugs/%d" % (self.url, bugdata.id), extinfo, duplicate)
def get_bug_old(self, id, duplicate=None): # Deprecated def get_bug_old(self, id, duplicate=None): # Deprecated
try: try:
@ -748,12 +747,12 @@ class Launchpad(IBugtracker):
# Try and find duplicates # Try and find duplicates
if bugdata['duplicate-of']: if bugdata['duplicate-of']:
data = self.get_bug_old(int(bugdata['duplicate-of']), duplicate or id)[0] data = self.get_bug_old(int(bugdata['duplicate-of']), duplicate or id)
data[8].append(bugdata['bug']) data[8].append(bugdata['bug'])
return [data] return data
return [(id, taskdata['task'], bugdata['title'], taskdata['importance'], taskdata['status'], return (id, taskdata['task'], bugdata['title'], taskdata['importance'], taskdata['status'],
assignee, "%s/bugs/%d" % (self.url, id), [], [])] assignee, "%s/bugs/%d" % (self.url, id), [], [])
# <rant> # <rant>
# Debbugs sucks donkeyballs # Debbugs sucks donkeyballs
@ -787,7 +786,7 @@ class Debbugs(IBugtracker):
status = 'Fixed' status = 'Fixed'
else: else:
status = 'Open' status = 'Open'
return [(id, raw['package'], raw['subject'], raw['severity'], status, '', "%s/%d" % (self.url, id), [], [])] return (id, raw['package'], raw['subject'], raw['severity'], status, '', "%s/%d" % (self.url, id), [], [])
except Exception as e: except Exception as e:
raise BugtrackerError(self.errparse % (self.description, e, url)) raise BugtrackerError(self.errparse % (self.description, e, url))
@ -800,7 +799,7 @@ class SourceForge(IBugtracker):
# registerBugtracker(name, url, desc, 'sourceforge') # registerBugtracker(name, url, desc, 'sourceforge')
return SourceForge(name, url, desc, 'sourceforge') return SourceForge(name, url, desc, 'sourceforge')
except: except:
return None pass
def get_bug(self, id): def get_bug(self, id):
url = "%s/%d/" % (self.url.replace('sourceforge.net', 'sourceforge.net/rest'), id) url = "%s/%d/" % (self.url.replace('sourceforge.net', 'sourceforge.net/rest'), id)
@ -815,8 +814,8 @@ class SourceForge(IBugtracker):
product = bug['labels'][0] product = bug['labels'][0]
if '_priority' in bug['custom_fields']: if '_priority' in bug['custom_fields']:
severity = 'Pri: %s' % bug['custom_fields']['_priority'] severity = 'Pri: %s' % bug['custom_fields']['_priority']
return [(id, product, bug['summary'], severity, ': '.join(bug['status'].split('-')), return (id, product, bug['summary'], severity, ': '.join(bug['status'].split('-')),
bug['assigned_to'], "%s/%d/" % (self.url, id), [], [])] bug['assigned_to'], "%s/%d/" % (self.url, id), [], [])
except Exception as e: except Exception as e:
raise BugtrackerError(self.errparse % (self.description, e, url)) raise BugtrackerError(self.errparse % (self.description, e, url))
@ -831,7 +830,7 @@ class GitHub(IBugtracker):
# registerBugtracker(name, url, desc, 'github') # registerBugtracker(name, url, desc, 'github')
return GitHub(name, url, desc, 'github') return GitHub(name, url, desc, 'github')
except: except:
return None pass
def get_bug(self, id): def get_bug(self, id):
url = "%s/%d" % (self.url.replace('github.com', 'api.github.com/repos'), id) url = "%s/%d" % (self.url.replace('github.com', 'api.github.com/repos'), id)
@ -852,7 +851,7 @@ class GitHub(IBugtracker):
assignee = bug['assignee']['login'] assignee = bug['assignee']['login']
else: else:
assignee = '' assignee = ''
return [(id, product, bug['title'], '', status, assignee, bug['html_url'], [], [])] return (id, product, bug['title'], '', status, assignee, bug['html_url'], [], [])
except Exception as e: except Exception as e:
raise BugtrackerError(self.errparse % (self.description, e, url)) raise BugtrackerError(self.errparse % (self.description, e, url))
@ -872,7 +871,7 @@ class Mantis(IBugtracker):
# registerBugtracker(name, url, desc, 'mantis') # registerBugtracker(name, url, desc, 'mantis')
return Mantis(name, url, desc, 'mantis') return Mantis(name, url, desc, 'mantis')
except: except:
return None pass
def get_bug(self, id): def get_bug(self, id):
url = "%s/view.php?id=%d" % (self.url, id) url = "%s/view.php?id=%d" % (self.url, id)
@ -887,7 +886,7 @@ class Mantis(IBugtracker):
if not raw: if not raw:
raise BugNotFoundError raise BugNotFoundError
try: try:
return [(id, raw['project']['name'], raw['summary'], raw['severity']['name'], raw['resolution']['name'], '', url, [], [])] return (id, raw['project']['name'], raw['summary'], raw['severity']['name'], raw['resolution']['name'], '', url, [], [])
except Exception as e: except Exception as e:
raise BugtrackerError(self.errparse % (self.description, e, url)) raise BugtrackerError(self.errparse % (self.description, e, url))
@ -904,7 +903,7 @@ class Trac(IBugtracker):
# registerBugtracker(name, url, desc, 'trac') # registerBugtracker(name, url, desc, 'trac')
return Trac(name, url, desc, 'trac') return Trac(name, url, desc, 'trac')
except: except:
return None pass
def get_bug(self, id): # This is still a little rough, but it works :) def get_bug(self, id): # This is still a little rough, but it works :)
url = "%s/%d" % (self.url, id) url = "%s/%d" % (self.url, id)
@ -936,7 +935,7 @@ class Trac(IBugtracker):
severity = rest[headers.index("priority")] severity = rest[headers.index("priority")]
if "owner" in headers: if "owner" in headers:
assignee = rest[headers.index("owner")] assignee = rest[headers.index("owner")]
return [(id, package, title, severity, status, assignee, url, [], [])] return (id, package, title, severity, status, assignee, url, [], [])
# Introspection is quite cool # Introspection is quite cool
defined_bugtrackers = {} defined_bugtrackers = {}