# -*- coding: utf-8 -*-
# Copyright (C) 2010, 2011 Anaël Verrier <elghinn@free.fr>
-# Copyright (C) 2015 kaliko <kaliko@azylum.org>
+# Copyright (C) 2015, 2020 kaliko <kaliko@azylum.org>
# 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
"""Gets bugs info from the BTS
"""
re_bugs = re_compile(r'(?<=#)(\d{6,7})')
+ re_pkg = re_compile(r'(?P<package>[0-9a-z.+-]+)$')
def __init__(self, bot):
Plugin.__init__(self, bot)
message = 'Invalid bug id: {id}'.format(**bug)
self.reply(msg, message)
else:
- message = {'mhtml': '<a href="%(url)s">#%(id)s</a>: %(package)s « %(summary)s »' % bug,
- 'mbody': '#%(id)s: %(package)s « %(summary)s » %(url)s' % bug}
+ message = {'mhtml': '<a href="%(url)s">#%(id)s</a>: %(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)
+