Merged in changes from bugzilla extension in mercurial 1.5.1.
1 # vim: set ts=4 sw=4 tw=99 et ft=python:
3 '''adds buglink template filter for turning bug numbers into links
5 This is a modified version of an extension in use at hg.mozilla.org
6 The original can be found here:
7 http://hg.mozilla.org/users/bsmedberg_mozilla.com/hgpoller/file/tip/buglink.py
9 To enable this extension:
12 buglink = /path/to/buglink.py
16 from mercurial import templatefilters
18 bugzilla = r'<a href="https://bugs.alliedmods.net/show_bug.cgi?id=\2">\1</a>'
19 bug_re = re.compile(r'''# bug followed by any sequence of numbers, or
20 # a standalone sequence of numbers
25 # a sequence of 5+ numbers preceded by whitespace
27 # numbers at the very beginning
33 flyspray = r'<a href="http://fs.alliedmods.net/index.php?do=details&task_id=\2">\1</a>'
34 amb_re = re.compile(r'''# amb followed by any sequence of numbers
43 log = bug_re.sub(bugzilla, x)
44 log = amb_re.sub(flyspray, log)
47 templatefilters.filters["buglink"] = buglink
49 if __name__ == '__main__':
53 ('bug 1', ('', 'bug 1', '1', '')),
54 ('bug 123456', ('', 'bug 123456', '123456', '')),
55 ('testb=1234x', ('test', 'b=1234', '1234', 'x')),
56 ('ab4665521e2f', None),
58 ('b=#12345', ('', 'b=#12345', '12345', '')),
59 ('GECKO_191a2_20080815_RELBRANCH', None),
60 ('12345 is a bug', ('', '12345', '12345', ' is a bug')),
61 (' 123456 whitespace!', (' ', '123456', '123456', ' whitespace!')),
62 ('changeset 938479a4c9df', None),
63 ('938479a4c9df', None),
66 class TestBugRe(unittest.TestCase):
67 def testreplacements(self):
68 for str, result in _tests:
72 pretext, text, bugid, posttext = result
73 resulttext = '%s<a href="https://bugs.alliedmods.net/show_bug.cgi?id=%s">%s</a>%s' % (pretext, bugid, text, posttext)
75 self.assertEqual(resulttext, buglink(str))