summaryrefslogtreecommitdiff
path: root/.config/terminator/plugins/susechangelog.py
blob: 24b9f17ba2f8c144e95c844f871200343337cadc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''Terminator plugin to make bug references clickable in RPM changelogs.'''

import re
from terminatorlib.plugin import URLHandler


AVAILABLE = ['BugzillaSuseURLHandler', 'FreedesktopURLHandler']


def _delimited(regex):
    return r'\b'+regex+r'\b'


# TODO: refactor, there are probably more elegant ways to re-use behaviour than
# class attributes.


class _ReferenceHandler(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)

    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={}'


# Other ideas from gtk3-devel's changelog:
# bgo#N
# bmo#N
# bnc#N
# bog#N
# boo#N
# bsc#N
# bug#N
# commit#X
# [Ff]ate#N
# glgo#GNOME/GTK#N
# kde#N