From: kaliko Date: Fri, 1 May 2020 14:52:44 +0000 (+0200) Subject: bugs: Add command argument to list package open bugs X-Git-Tag: 0.1.0~27 X-Git-Url: https://git.kaliko.me/?p=sid.git;a=commitdiff_plain;h=034db6aba932f1e955732ad8f7bb7f226e8f9231 bugs: Add command argument to list package open bugs --- diff --git a/sid/bts.py b/sid/bts.py index 254a923..201df9a 100644 --- a/sid/bts.py +++ b/sid/bts.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (C) 2010, 2011 Anaël Verrier -# Copyright (C) 2015 kaliko +# Copyright (C) 2015, 2020 kaliko # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ class Bugs(Plugin): """Gets bugs info from the BTS """ re_bugs = re_compile(r'(?<=#)(\d{6,7})') + re_pkg = re_compile(r'(?P[0-9a-z.+-]+)$') def __init__(self, bot): Plugin.__init__(self, bot) @@ -58,13 +59,35 @@ class Bugs(Plugin): message = 'Invalid bug id: {id}'.format(**bug) self.reply(msg, message) else: - message = {'mhtml': '#%(id)s: %(package)s « %(summary)s »' % bug, - 'mbody': '#%(id)s: %(package)s « %(summary)s » %(url)s' % bug} + message = {'mhtml': '#%(id)s: %(package)s “ %(summary)s ”' % bug, + 'mbody': '#%(id)s: %(package)s “ %(summary)s ” %(url)s' % bug} self.reply(msg, message) @botcmd - def bugs(self, message, args): - """ intercepts bugs number in any message, looking for string like #629234 - !bugs : nothing yet. + def bugs(self, rcv, args): + """ intercepts bugs number in any message, looking for string like #629234 and display bug summary. + !bugs pkg-name : Returns latest bug reports if any """ - return None + if not args: + return + if len(args) > 1: + self.log.info('more than one packages provided') + pkg = Bugs.re_pkg.match(args[0]) + if not pkg: + msg = 'Wrong package name format re: "{}"'.format(Bugs.re_pkg.pattern) + self.reply(rcv, msg) + return + reports_ids = debianbts.get_bugs(status='open', **pkg.groupdict()) + if not reports_ids: + self.reply(rcv, 'No open bugs for "{}"'.format(pkg.string)) + return + reports = debianbts.get_status(reports_ids) + reports = sorted(reports, key=lambda r: r.date) + rprt_nb = len(reports) + msg = ['Open reports for {1} (total {0})'.format(rprt_nb, pkg.string)] + # Reverse and take last reports + for rep in reports[::-1][:4]: + msg.append('{r.bug_num}: {r.date:%Y-%m-%d} {r.subject}'.format(r=rep)) + message = {'mbody': '\n'.join(msg)} + self.reply(rcv, message) +