diff --git a/Bugtracker/__init__.py b/Bugtracker/__init__.py index f62b8b0..d7d0918 100644 --- a/Bugtracker/__init__.py +++ b/Bugtracker/__init__.py @@ -24,7 +24,7 @@ import supybot.world as world from imp import reload -__version__ = "2.9.0" +__version__ = "3.0.0" __author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com") __contributors__ = { supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'], diff --git a/Bugtracker/plugin.py b/Bugtracker/plugin.py index 2f2b991..8176889 100644 --- a/Bugtracker/plugin.py +++ b/Bugtracker/plugin.py @@ -319,8 +319,8 @@ class Bugtracker(callbacks.PluginRegexp): return irc.error(str(e)) else: - for r in report: - irc.reply(r) + if report: + irc.reply(report) 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\d+)/?" @@ -348,8 +348,8 @@ class Bugtracker(callbacks.PluginRegexp): if self.registryValue('replyWhenNotFound'): irc.error("Could not find %s bug %s" % (tracker.description, match.group('bug'))) else: - for r in report: - irc.reply(r) + if report: + irc.reply(report) # Only useful to Launchpad developers def oopsSnarfer(self, irc, msg, match): @@ -423,76 +423,75 @@ class Bugtracker(callbacks.PluginRegexp): elif '/ticket/' in snarfurl: tracker = Trac().get_tracker(snarfurl) else: - return None + return if tracker: self.db[tracker.name] = tracker self.shorthand = utils.abbrev(list(self.db.keys())) return tracker - return None 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): - return [] + return - for r in tracker.get_bug(id): - (bid, product, title, severity, status, assignee, url, extinfo, duplicate) = r + bugdata = tracker.get_bug(id) + if not bugdata: + return - if duplicate and not self.is_ok(channel, tracker, bid): - continue + (bid, product, title, severity, status, assignee, url, extinfo, duplicate) = bugdata - bugtype = re.match(r'.*/(feature-)?(?Prequest|patch|todo|issue|pull|ticket)(e?s)?/[0-9]+/?$', url) - if do_tracker and tracker.trackertype != 'github': - if re.match(r'.*/(bugs|feature-requests|patches|todo|issues|pulls?|ticket)/?$', tracker.description): - report = '%s %d' % (tracker.description, bid) - else: - if bugtype: - report = '%s %s %d' % (tracker.description, bugtype.group('type'), bid) - else: - report = '%s bug %d' % (tracker.description, bid) + if duplicate and not self.is_ok(channel, tracker, bid): + return + + bugtype = re.match(r'.*/(feature-)?(?Prequest|patch|todo|issue|pull|ticket)(e?s)?/[0-9]+/?$', url) + if do_tracker and tracker.trackertype != 'github': + if re.match(r'.*/(bugs|feature-requests|patches|todo|issues|pulls?|ticket)/?$', tracker.description): + report = '%s %d' % (tracker.description, bid) else: if bugtype: - report = '%s %d' % (bugtype.group('type').title(), bid) + report = '%s %s %d' % (tracker.description, bugtype.group('type'), bid) 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: - report += ' in %s' % product + if product: + report += ' in %s' % product - report += ' "%s"' % title.replace('"', "'").strip() + report += ' "%s"' % title.replace('"', "'").strip() - if do_extinfo and extinfo: - report += ' (%s)' % ', '.join(extinfo) + if do_extinfo and extinfo: + report += ' (%s)' % ', '.join(extinfo) - if do_assignee and assignee: - report += ' (assigned: %s)' % assignee + if do_assignee and assignee: + report += ' (assigned: %s)' % assignee - severity_status = [] - 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 status.split())) - report += ' [%s]' % ', '.join(severity_status) + severity_status = [] + 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 status.split())) + report += ' [%s]' % ', '.join(severity_status) - if duplicate: - report += ' [duplicate: %s]' % duplicate[0] + if duplicate: + report += ' [duplicate: %s]' % duplicate[0] - if do_url: - report += ' %s' % url + if do_url: + report += ' %s' % url - if len(report) > message_max: - report_parts = report.split('"') - report_start = report_parts[0] - report_end = report_parts[-1] - report_title = '"'.join(report_parts[1:-1]) - title_max = message_max - len(report_start) - len(report_end) - 5 - report_title_cut = report_title[:title_max].rsplit(None, 1)[0] + '...' - report = '%s"%s"%s' % (report_start, report_title_cut, report_end) + message_max = 450 - len(channel) + if len(report) > message_max: + report_parts = report.split('"') + report_start = report_parts[0] + report_end = report_parts[-1] + report_title = '"'.join(report_parts[1:-1]) + title_max = message_max - len(report_start) - len(report_end) - 5 + 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 reports + return report # Define all bugtrackers class IBugtracker: @@ -531,7 +530,7 @@ class Bugzilla(IBugtracker): # registerBugtracker(name, url, desc, 'bugzilla') return Bugzilla(name, url, desc, 'bugzilla') except: - return None + pass def get_bug(self, id): url = "%s/rest/bug/%d" % (self.url, id) @@ -553,8 +552,8 @@ class Bugzilla(IBugtracker): assignee = bug['assigned_to_detail']['name'] else: assignee = '' - return [(id, bug['product'], bug['summary'], bug['severity'], status, assignee, - "%s/show_bug.cgi?id=%d" % (self.url, id), [], [])] + return (id, bug['product'], bug['summary'], bug['severity'], status, assignee, + "%s/show_bug.cgi?id=%d" % (self.url, id), [], []) except Exception as e: raise BugtrackerError(self.errparse % (self.description, e, url)) @@ -590,7 +589,7 @@ class Bugzilla(IBugtracker): assignee = '' except Exception as e: 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): statuses = ("Unknown", "Invalid", "Opinion", "Won't Fix", "Fix Released", "Fix Committed", "New", @@ -715,8 +714,8 @@ class Launchpad(IBugtracker): raise BugNotFoundError 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, - assignee, "%s/bugs/%d" % (self.url, bugdata.id), extinfo, duplicate)] + return (bugdata.id, taskdata.bug_target_display_name, bugdata.title, taskdata.importance, taskdata.status, + assignee, "%s/bugs/%d" % (self.url, bugdata.id), extinfo, duplicate) def get_bug_old(self, id, duplicate=None): # Deprecated try: @@ -748,12 +747,12 @@ class Launchpad(IBugtracker): # Try and find duplicates 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']) - return [data] + return data - return [(id, taskdata['task'], bugdata['title'], taskdata['importance'], taskdata['status'], - assignee, "%s/bugs/%d" % (self.url, id), [], [])] + return (id, taskdata['task'], bugdata['title'], taskdata['importance'], taskdata['status'], + assignee, "%s/bugs/%d" % (self.url, id), [], []) # # Debbugs sucks donkeyballs @@ -787,7 +786,7 @@ class Debbugs(IBugtracker): status = 'Fixed' else: 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: raise BugtrackerError(self.errparse % (self.description, e, url)) @@ -800,7 +799,7 @@ class SourceForge(IBugtracker): # registerBugtracker(name, url, desc, 'sourceforge') return SourceForge(name, url, desc, 'sourceforge') except: - return None + pass def get_bug(self, id): url = "%s/%d/" % (self.url.replace('sourceforge.net', 'sourceforge.net/rest'), id) @@ -815,8 +814,8 @@ class SourceForge(IBugtracker): product = bug['labels'][0] if '_priority' in bug['custom_fields']: severity = 'Pri: %s' % bug['custom_fields']['_priority'] - return [(id, product, bug['summary'], severity, ': '.join(bug['status'].split('-')), - bug['assigned_to'], "%s/%d/" % (self.url, id), [], [])] + return (id, product, bug['summary'], severity, ': '.join(bug['status'].split('-')), + bug['assigned_to'], "%s/%d/" % (self.url, id), [], []) except Exception as e: raise BugtrackerError(self.errparse % (self.description, e, url)) @@ -831,7 +830,7 @@ class GitHub(IBugtracker): # registerBugtracker(name, url, desc, 'github') return GitHub(name, url, desc, 'github') except: - return None + pass def get_bug(self, 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'] else: 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: raise BugtrackerError(self.errparse % (self.description, e, url)) @@ -872,7 +871,7 @@ class Mantis(IBugtracker): # registerBugtracker(name, url, desc, 'mantis') return Mantis(name, url, desc, 'mantis') except: - return None + pass def get_bug(self, id): url = "%s/view.php?id=%d" % (self.url, id) @@ -887,7 +886,7 @@ class Mantis(IBugtracker): if not raw: raise BugNotFoundError 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: raise BugtrackerError(self.errparse % (self.description, e, url)) @@ -904,7 +903,7 @@ class Trac(IBugtracker): # registerBugtracker(name, url, desc, 'trac') return Trac(name, url, desc, 'trac') except: - return None + pass def get_bug(self, id): # This is still a little rough, but it works :) url = "%s/%d" % (self.url, id) @@ -936,7 +935,7 @@ class Trac(IBugtracker): severity = rest[headers.index("priority")] if "owner" in headers: 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 defined_bugtrackers = {}