]> kaliko git repositories - sid.git/blobdiff - sid/bts.py
Bump version
[sid.git] / sid / bts.py
index 201df9a0fb5c8bfbb3704d520567f0fa842a78df..fa882444aa4c32e0bc25fdf1e0969892d05fe0c6 100644 (file)
@@ -1,20 +1,11 @@
 # -*- coding: utf-8 -*-
+# SPDX-FileCopyrightText: 2015, 2021 kaliko <kaliko@azylum.org>
+# SPDX-FileCopyrightText: 2010, 2011 Anaël Verrier <elghinn@free.fr>
+# SPDX-License-Identifier: GPL-3.0-or-later
+"""Intercepts bugs numbers in MUC messages and send info about it
 
-# Copyright (C) 2010, 2011 Anaël Verrier <elghinn@free.fr>
-# 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
-# the Free Software Foundation, version 3 only.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
+>>> from sid.bts import Bugs
+"""
 
 from re import compile as re_compile
 
@@ -25,21 +16,28 @@ from .plugin import Plugin, botcmd
 
 class Bugs(Plugin):
     """Gets bugs info from the BTS
+
+    .. note::
+      This plugin depends on external module: **python-debianbts**
     """
-    re_bugs = re_compile(r'(?<=#)(\d{6,7})')
+    #: Bug id regexp, intercepts bug id in strings : "#629234", "bugs.debian.org/629234" and "bugreport.cgi?bug=629234"
+    re_bugs = re_compile(r'(?:(?<=#)|(?<=bugreport\.cgi\?bug=)|(?<=bugs\.debian\.org/))(\d{6,7})')
+    #: Package name regexp
     re_pkg = re_compile(r'(?P<package>[0-9a-z.+-]+)$')
 
     def __init__(self, bot):
         Plugin.__init__(self, bot)
-        bot.add_event_handler("muc::%s::message" % self.bot.room, self.muc_message)
+        bot.add_event_handler("muc::%s::message" %
+                              self.bot.room, self.muc_message)
 
     def muc_message(self, msg):
-        """Handler method dealing with MUC incoming messages"""
+        """Handler method dealing with MUC incoming messages.
+
+        Intercepts bugs number in MUC messages (as #629234), replies a bug
+        summary."""
         # Does not reply to myself
         if msg['mucnick'] == self.bot.nick:
             return
-        if '#' not in msg['body']:
-            return
         bugs = list()
         for bug_id in set(Bugs.re_bugs.findall(msg['body'].strip())):
             self.log.debug('got bug id: %s', bug_id)
@@ -65,8 +63,9 @@ class Bugs(Plugin):
 
     @botcmd
     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
+        """Gets bugs info from the BTS
+
+        ``!bugs pkg-name`` : Returns latest bug reports if any
         """
         if not args:
             return
@@ -83,11 +82,9 @@ class Bugs(Plugin):
             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)]
+        msg = ['Latest reports for {1} (total {0})'.format(len(reports), 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)
-