|
ds@0
|
1 |
# vim: set ts=4 sw=4 tw=99 et ft=python: |
|
ds@0
|
2 |
|
|
ds@0
|
3 |
'''adds buglink template filter for turning bug numbers into links |
|
ds@0
|
4 |
|
|
ds@0
|
5 |
This is a modified version of an extension in use at hg.mozilla.org |
|
ds@0
|
6 |
The original can be found here: |
|
ds@0
|
7 |
http://hg.mozilla.org/users/bsmedberg_mozilla.com/hgpoller/file/tip/buglink.py |
|
ds@0
|
8 |
|
|
ds@0
|
9 |
To enable this extension: |
|
ds@0
|
10 |
|
|
ds@0
|
11 |
[extensions] |
|
ds@0
|
12 |
buglink = /path/to/buglink.py |
|
ds@0
|
13 |
''' |
|
ds@0
|
14 |
|
|
ds@0
|
15 |
import re |
|
ds@0
|
16 |
from mercurial import templatefilters |
|
ds@0
|
17 |
|
|
ds@0
|
18 |
bugzilla = r'<a href="https://bugs.alliedmods.net/show_bug.cgi?id=\2">\1</a>' |
|
ds@0
|
19 |
bug_re = re.compile(r'''# bug followed by any sequence of numbers, or |
|
ds@0
|
20 |
# a standalone sequence of numbers |
|
ds@0
|
21 |
( |
|
ds@0
|
22 |
(?: |
|
ds@0
|
23 |
bug | |
|
ds@0
|
24 |
b= | |
|
ds@0
|
25 |
# a sequence of 5+ numbers preceded by whitespace |
|
ds@0
|
26 |
(?=\b\#?\d{5,}\b) | |
|
ds@0
|
27 |
# numbers at the very beginning |
|
ds@0
|
28 |
^(?=\d\b) |
|
ds@0
|
29 |
) |
|
ds@0
|
30 |
(?:\s*\#?)(\d+) |
|
ds@0
|
31 |
)''', re.I | re.X) |
|
ds@0
|
32 |
|
|
ds@0
|
33 |
flyspray = r'<a href="http://fs.alliedmods.net/index.php?do=details&task_id=\2">\1</a>' |
|
ds@0
|
34 |
amb_re = re.compile(r'''# amb followed by any sequence of numbers |
|
ds@0
|
35 |
( |
|
ds@0
|
36 |
(?: |
|
ds@0
|
37 |
amb |
|
ds@0
|
38 |
) |
|
ds@0
|
39 |
(?:\s*\#?)(\d+) |
|
ds@0
|
40 |
)''', re.I | re.X) |
|
ds@0
|
41 |
|
|
ds@0
|
42 |
def buglink(x): |
|
ds@0
|
43 |
log = bug_re.sub(bugzilla, x) |
|
ds@0
|
44 |
log = amb_re.sub(flyspray, log) |
|
ds@0
|
45 |
return log |
|
ds@0
|
46 |
|
|
ds@0
|
47 |
templatefilters.filters["buglink"] = buglink |
|
ds@0
|
48 |
|
|
ds@0
|
49 |
if __name__ == '__main__': |
|
ds@0
|
50 |
import unittest |
|
ds@0
|
51 |
|
|
ds@0
|
52 |
_tests = ( |
|
ds@0
|
53 |
('bug 1', ('', 'bug 1', '1', '')), |
|
ds@0
|
54 |
('bug 123456', ('', 'bug 123456', '123456', '')), |
|
ds@0
|
55 |
('testb=1234x', ('test', 'b=1234', '1234', 'x')), |
|
ds@0
|
56 |
('ab4665521e2f', None), |
|
ds@0
|
57 |
('Aug 2008', None), |
|
ds@0
|
58 |
('b=#12345', ('', 'b=#12345', '12345', '')), |
|
ds@0
|
59 |
('GECKO_191a2_20080815_RELBRANCH', None), |
|
ds@0
|
60 |
('12345 is a bug', ('', '12345', '12345', ' is a bug')), |
|
ds@0
|
61 |
(' 123456 whitespace!', (' ', '123456', '123456', ' whitespace!')), |
|
ds@0
|
62 |
('changeset 938479a4c9df', None), |
|
ds@0
|
63 |
('938479a4c9df', None), |
|
ds@0
|
64 |
) |
|
ds@0
|
65 |
|
|
ds@0
|
66 |
class TestBugRe(unittest.TestCase): |
|
ds@0
|
67 |
def testreplacements(self): |
|
ds@0
|
68 |
for str, result in _tests: |
|
ds@0
|
69 |
if result is None: |
|
ds@0
|
70 |
resulttext = str |
|
ds@0
|
71 |
else: |
|
ds@0
|
72 |
pretext, text, bugid, posttext = result |
|
ds@0
|
73 |
resulttext = '%s<a href="https://bugs.alliedmods.net/show_bug.cgi?id=%s">%s</a>%s' % (pretext, bugid, text, posttext) |
|
ds@0
|
74 |
|
|
ds@0
|
75 |
self.assertEqual(resulttext, buglink(str)) |
|
ds@0
|
76 |
|
|
ds@0
|
77 |
unittest.main() |