summaryrefslogtreecommitdiff
path: root/.config/terminator/plugins/susechangelog.py
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2018-06-24 11:28:32 +0200
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2018-06-24 11:28:32 +0200
commit087b357d3b6c479b11bf3fd1d04fc74ffb833a21 (patch)
treee7f33efc6529fd58c5804b8d543106ecc52851c8 /.config/terminator/plugins/susechangelog.py
parenta2727dc7612bd08f8171267139f01d22cf3af59c (diff)
downloaddotfiles-087b357d3b6c479b11bf3fd1d04fc74ffb833a21.tar.xz
Refactor bug-tracker plugin
Of course, at some point I'll have to deal with a format that does not fit in this simple regex… 🤷
Diffstat (limited to '.config/terminator/plugins/susechangelog.py')
-rw-r--r--.config/terminator/plugins/susechangelog.py44
1 files changed, 15 insertions, 29 deletions
diff --git a/.config/terminator/plugins/susechangelog.py b/.config/terminator/plugins/susechangelog.py
index 24b9f17..626f483 100644
--- a/.config/terminator/plugins/susechangelog.py
+++ b/.config/terminator/plugins/susechangelog.py
@@ -4,43 +4,29 @@ import re
from terminatorlib.plugin import URLHandler
-AVAILABLE = ['BugzillaSuseURLHandler', 'FreedesktopURLHandler']
+AVAILABLE = ['SuseChangelogURLHandler']
-def _delimited(regex):
- return r'\b'+regex+r'\b'
+_TRACKERS = {
+ 'bsc': 'https://bugzilla.suse.com/show_bug.cgi?id={}',
+ 'fdo': 'https://bugs.freedesktop.org/show_bug.cgi?id={}'
+}
+_MATCH = r'(?P<tracker>{t})#(?P<id>{i})'.format(
+ t='|'.join(_TRACKERS),
+ i='[0-9]+(?:#c[0-9]+)?'
+)
-# TODO: refactor, there are probably more elegant ways to re-use behaviour than
-# class attributes.
-
-class _ReferenceHandler(URLHandler):
+class SuseChangelogURLHandler(URLHandler):
capabilities = ['url_handler']
- _delimiter = '#'
-
- def __init__(self, *args, **kwargs):
- self.match = _delimited(self._prefix+self._delimiter+self._id)
- super(_ReferenceHandler, self).__init__(*args, **kwargs)
+ match = r'\b'+_MATCH+r'\b'
def callback(self, ref):
- bug_id = re.search(self._id, ref).group()
- url = self._template.format(bug_id)
- return url
-
-
-class BugzillaSuseURLHandler(_ReferenceHandler):
- handler_name = 'bugzilla.suse.com'
- _prefix = 'bsc'
- _id = '[0-9]+(#c[0-9]+)?'
- _template = 'https://bugzilla.suse.com/show_bug.cgi?id={}'
-
-
-class FreedesktopURLHandler(_ReferenceHandler):
- handler_name = 'bugs.freedesktop.org'
- _prefix = 'fdo'
- _id = '[0-9]+'
- _template = 'https://bugs.freedesktop.org/show_bug.cgi?id={}'
+ fields = re.match(_MATCH, ref).groupdict()
+ template = _TRACKERS[fields['tracker']]
+ bug_id = fields['id']
+ return template.format(bug_id)
# Other ideas from gtk3-devel's changelog: