annotate extensions/local_replace.py @ 560:0d0e7ce385e7 default tip

Make the CLA check case-insensitive, and use stringFind() instead of filter().
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 11 Sep 2018 18:31:06 -0700
parents 7d4942e1ce43
children
rev   line source
98
7b1482bfa197 Replace #<number> with a hyperlink to issue<number>, as proposed in
erik.forsberg
parents:
diff changeset
1 import re
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
2 import cgi
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
3 from roundup import hyperdb
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
4 from roundup.cgi.templating import register_propclass, StringHTMLProperty
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
5
98
7b1482bfa197 Replace #<number> with a hyperlink to issue<number>, as proposed in
erik.forsberg
parents:
diff changeset
6
323
381e22631263 Use local_replace update for hg migration.
georg.brandl
parents: 308
diff changeset
7 # pre-hg migration
381e22631263 Use local_replace update for hg migration.
georg.brandl
parents: 308
diff changeset
8 '''
239
8295b17a11da Refactor the regex list, use one regex for [r,rev,revision], add comments, indent properly, avoid long lines.
ezio.melotti
parents: 238
diff changeset
9 substitutions = [
8295b17a11da Refactor the regex list, use one regex for [r,rev,revision], add comments, indent properly, avoid long lines.
ezio.melotti
parents: 238
diff changeset
10 # r12345, r 12345, rev12345, rev 12345, revision12345, revision 12345
270
d8b92a5e2bac Tweak regex to avoid linking to revisions when they appear in the query string of an URL.
ezio.melotti
parents: 265
diff changeset
11 (re.compile(r'\b(?<![/?&;])(?P<revstr>r(ev(ision)?)?\s*)(?P<revision>\d+)'),
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
12 r'<a href="http://svn.python.org/view?rev=\g<revision>'
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
13 r'&view=rev">\g<revstr>\g<revision></a>'),
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
14
239
8295b17a11da Refactor the regex list, use one regex for [r,rev,revision], add comments, indent properly, avoid long lines.
ezio.melotti
parents: 238
diff changeset
15 # Lib/somefile.py, Modules/somemodule.c, Doc/somedocfile.rst, ...
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
16 (re.compile(r'(?P<sep>(?<!\w/)|(?<!\w)/)(?P<path>(?:Demo|Doc|Grammar|'
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
17 r'Include|Lib|Mac|Misc|Modules|Parser|PC|PCbuild|Python|'
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
18 'RISCOS|Tools|Objects)/[-.a-zA-Z0-9_/]+[a-zA-Z0-9]/?)'),
265
6a5814ea17ab Trunk is dead, link to py3k.
ezio.melotti
parents: 264
diff changeset
19 r'<a href="http://svn.python.org/view/python/branches/'
6a5814ea17ab Trunk is dead, link to py3k.
ezio.melotti
parents: 264
diff changeset
20 r'py3k/\g<path>">\g<sep>\g<path></a>'),
239
8295b17a11da Refactor the regex list, use one regex for [r,rev,revision], add comments, indent properly, avoid long lines.
ezio.melotti
parents: 238
diff changeset
21 ]
323
381e22631263 Use local_replace update for hg migration.
georg.brandl
parents: 308
diff changeset
22 '''
98
7b1482bfa197 Replace #<number> with a hyperlink to issue<number>, as proposed in
erik.forsberg
parents:
diff changeset
23
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
24
368
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
25 def make_file_link(match):
528
4ede54907083 Convert files and traceback links in messages from hg.python.org to GitHub.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 526
diff changeset
26 """Convert files to links to the GitHub repo."""
531
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
27 baseurl = 'https://github.com/python/cpython/blob/'
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
28 branch = match.group('v') or 'master/' # the match includes the '/'
368
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
29 path = match.group('path')
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
30 lnum = match.group('lnum') or '' # the match includes the ':'
531
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
31 url = baseurl + branch + path
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
32 if not path.endswith('/'):
368
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
33 # files without and with line number
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
34 if not lnum:
531
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
35 return '<a href="%s">%s</a>' % (url, path)
368
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
36 else:
531
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
37 return '<a href="%s#L%s">%s%s</a>' % (url, lnum[1:], path, lnum)
368
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
38 else:
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
39 # dirs
531
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
40 return '<a href="%s">%s</a>%s' % (url, path, lnum)
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
41
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
42
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
43 def guess_version(path):
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
44 """Search for Python version hints in the file path."""
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
45 match = re.search(r'((?<=[Pp]ython)[23]\d|[23]\.\d)', path)
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
46 if not match:
528
4ede54907083 Convert files and traceback links in messages from hg.python.org to GitHub.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 526
diff changeset
47 return 'master'
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
48 version = match.group(1)
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
49 if '.' not in version:
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
50 version = '.'.join(version)
528
4ede54907083 Convert files and traceback links in messages from hg.python.org to GitHub.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 526
diff changeset
51 if version in ['2.3', '2.4', '2.5', '2.6', '2.7', '3.1', '3.2',
4ede54907083 Convert files and traceback links in messages from hg.python.org to GitHub.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 526
diff changeset
52 '3.3', '3.4', '3.5', '3.6', '3.7', '3.8', '3.9']:
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
53 return version
528
4ede54907083 Convert files and traceback links in messages from hg.python.org to GitHub.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 526
diff changeset
54 return 'master'
368
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
55
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
56
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
57 def make_traceback_link(match):
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
58 """Convert the file/line in the traceback lines in a link."""
528
4ede54907083 Convert files and traceback links in messages from hg.python.org to GitHub.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 526
diff changeset
59 baseurl = 'https://github.com/python/cpython/blob/'
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
60 path = match.group('path') # first part of the path
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
61 branch = guess_version(match.group('fullpath')) # guessed branch
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
62 file = match.group('file') # second part after Lib/
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
63 nfile = file.replace('\\', '/') # normalize the path separators
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
64 lnum = match.group('lnum')
528
4ede54907083 Convert files and traceback links in messages from hg.python.org to GitHub.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 526
diff changeset
65 return ('File "%s<a href="%s%s/Lib/%s#L%s">%s</a>", line %s' %
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
66 (path, baseurl, branch, nfile, lnum, file, lnum))
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
67
370
36e532ed90a0 #399: automatically link to PEPs in the messages.
ezio.melotti
parents: 369
diff changeset
68 def make_pep_link(match):
36e532ed90a0 #399: automatically link to PEPs in the messages.
ezio.melotti
parents: 369
diff changeset
69 text = match.group(0)
36e532ed90a0 #399: automatically link to PEPs in the messages.
ezio.melotti
parents: 369
diff changeset
70 pepnum = match.group(1).zfill(4)
36e532ed90a0 #399: automatically link to PEPs in the messages.
ezio.melotti
parents: 369
diff changeset
71 return '<a href="http://www.python.org/dev/peps/pep-%s/">%s</a>' % (pepnum, text)
36e532ed90a0 #399: automatically link to PEPs in the messages.
ezio.melotti
parents: 369
diff changeset
72
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
73
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
74 # these regexs have test in tests/test_local_replace.py
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
75
530
626ae2064f83 Tweak regex to prevent incorrect URL linkification.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 528
diff changeset
76 seps = r'\b(?<![-/?&;=_:])' # these chars should not precede the targets
308
df1194ba4667 Add new replacement rules for use after hg migration.
georg.brandl
parents: 270
diff changeset
77 substitutions = [
523
18a7bc95ec31 #610: automatically convert Git csids in messages to links. Patch by Brett Cannon.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 522
diff changeset
78 # deadbeeffeed (hg hashes with exactly twelve or forty chars,
18a7bc95ec31 #610: automatically convert Git csids in messages to links. Patch by Brett Cannon.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 522
diff changeset
79 # git has 10 or more as it grows as time goes on)
18a7bc95ec31 #610: automatically convert Git csids in messages to links. Patch by Brett Cannon.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 522
diff changeset
80 (re.compile(r'%s(?P<revision>(git|hg)?[a-fA-F0-9]{40})\b' % seps),
324
6592f47dfc82 Fix branch name.
georg.brandl
parents: 323
diff changeset
81 r'<a href="http://hg.python.org/lookup/\g<revision>">\g<revision></a>'),
523
18a7bc95ec31 #610: automatically convert Git csids in messages to links. Patch by Brett Cannon.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 522
diff changeset
82 (re.compile(r'%s(?P<revision>(git|hg)?[a-fA-F0-9]{10,12})\b' % seps),
324
6592f47dfc82 Fix branch name.
georg.brandl
parents: 323
diff changeset
83 r'<a href="http://hg.python.org/lookup/\g<revision>">\g<revision></a>'),
308
df1194ba4667 Add new replacement rules for use after hg migration.
georg.brandl
parents: 270
diff changeset
84
419
4d464bffb7e1 Make "rev. 12345" work too.
ezio.melotti
parents: 405
diff changeset
85 # r12345, r 12345, rev12345, rev. 12345, revision12345, revision 12345
460
441435cd65f8 Factor out some code and fix a couple of bugs.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 457
diff changeset
86 (re.compile(r'%s(?P<revstr>r\.?(ev\.?(ision)?)?\s*)(?P<revision>\d{4,})' % seps),
377
38ee1db61685 Linkify hg changesets id before svn revisions.
ezio.melotti
parents: 370
diff changeset
87 r'<a href="http://hg.python.org/lookup/r\g<revision>">\g<revstr>\g<revision></a>'),
38ee1db61685 Linkify hg changesets id before svn revisions.
ezio.melotti
parents: 370
diff changeset
88
368
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
89 # Lib/somefile.py, Lib/somefile.py:123, Modules/somemodule.c:123, ...
531
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
90 (re.compile(r'%s(?P<v>2\.[0-7]/|3\.\d/)?(?P<path>(?:Demo|Doc|Grammar|'
308
df1194ba4667 Add new replacement rules for use after hg migration.
georg.brandl
parents: 270
diff changeset
91 r'Include|Lib|Mac|Misc|Modules|Parser|PC|PCbuild|Python|'
531
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
92 r'RISCOS|Tools|Programs|Objects)/'
0b314baf6c8b Update file linkification to support Python version numbers.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 530
diff changeset
93 r'[-.\w/]+[a-zA-Z0-9]/?)(?P<lnum>:\d{1,5})?' % seps),
368
14734fa06da8 Link to a specific line when :NNN is added after a file name. Also update and add more tests.
ezio.melotti
parents: 324
diff changeset
94 make_file_link),
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
95
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
96 # traceback lines: File "Lib/somefile.py", line 123 in some_func
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
97 # note: this regex is not 100% accurate, it might get the wrong part of
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
98 # the path or link to non-existing files, but it usually works fine
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
99 (re.compile(r'File "(?P<fullpath>(?P<path>[-.\w/\\:]+(?<!var)[/\\][Ll]ib[/\\]'
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
100 r'(?!.*site-packages)(python[\d.]*[/\\])?)(?P<file>[-.\w/\\]+?\.py))", '
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
101 r'line (?P<lnum>\d{1,5})'),
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
102 make_traceback_link),
370
36e532ed90a0 #399: automatically link to PEPs in the messages.
ezio.melotti
parents: 369
diff changeset
103
36e532ed90a0 #399: automatically link to PEPs in the messages.
ezio.melotti
parents: 369
diff changeset
104 # PEP 8, PEP8, PEP 0008, ...
460
441435cd65f8 Factor out some code and fix a couple of bugs.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 457
diff changeset
105 (re.compile(r'%s\b(?<![/=-])PEP\s*(\d{1,4})(?!/)\b' % seps, re.I),
370
36e532ed90a0 #399: automatically link to PEPs in the messages.
ezio.melotti
parents: 369
diff changeset
106 make_pep_link),
392
c5288b884365 Add linkification for the devguide.
ezio.melotti
parents: 379
diff changeset
107
c5288b884365 Add linkification for the devguide.
ezio.melotti
parents: 379
diff changeset
108 # devguide
460
441435cd65f8 Factor out some code and fix a couple of bugs.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 457
diff changeset
109 (re.compile(r'%s(devguide(?:/\w+(?:.html)?(?:#[\w-]+)?)?)' % seps),
392
c5288b884365 Add linkification for the devguide.
ezio.melotti
parents: 379
diff changeset
110 r'<a href="http://docs.python.org/\1">\1</a>'),
308
df1194ba4667 Add new replacement rules for use after hg migration.
georg.brandl
parents: 270
diff changeset
111 ]
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
112
369
f41b8b899620 Link to file/lines in the tracebacks. Also refactor and add more tests.
ezio.melotti
parents: 368
diff changeset
113
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
114 # if the issue number is too big the db will explode -- limit it to 7 digits
533
d58a43bb89e3 Improve the test runner for local_replace and fix a bug it unveiled.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 531
diff changeset
115 issue_re = re.compile(r'(?P<text>((?<!\w)\#|\b(?<![-/_])(issue|bpo-))'
d58a43bb89e3 Improve the test runner for local_replace and fix a bug it unveiled.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 531
diff changeset
116 r'\s*(?P<id>1?\d{1,6}))\b', re.I)
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
117
521
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
118 # PR number, pull request number, pullrequest number
537
7d4942e1ce43 Linkify GHXXXX, GH-XXXX, and PR-XXXX too.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 534
diff changeset
119 pullrequest_re = re.compile(r'(?P<text>(\b(?<![-/_])(PR-?|GH-?|pull\s*request))\s*'
521
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
120 r'(?P<pr_no>\d+))\b', re.I)
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
121
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
122
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
123 class PyDevStringHTMLProperty(StringHTMLProperty):
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
124 def _hyper_repl(self, match):
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
125 """
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
126 Override the original method and change it to still linkify URLs and
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
127 emails but avoid linkification of issues and other items
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
128 (except messages and files).
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
129 """
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
130 if match.group('url'):
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
131 return self._hyper_repl_url(match, '<a href="%s">%s</a>%s')
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
132 elif match.group('email'):
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
133 return self._hyper_repl_email(match, '<a href="mailto:%s">%s</a>')
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
134 elif (len(match.group('id')) < 10 and
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
135 match.group('class') and
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
136 match.group('class').lower() in ('msg', 'file')):
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
137 # linkify msgs but not issues and other things
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
138 return self._hyper_repl_item(match,
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
139 '<a href="%(cls)s%(id)s">%(item)s</a>')
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
140 else:
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
141 # just return the matched text
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
142 return match.group(0)
98
7b1482bfa197 Replace #<number> with a hyperlink to issue<number>, as proposed in
erik.forsberg
parents:
diff changeset
143
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
144 def pydev_hyperlinked(self):
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
145 """Create python-dev-specific links."""
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
146 # first do the normal linkification (without linkify the issues)
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
147 message = self.plain(hyperlink=1)
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
148 # then add links for revision numbers and paths
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
149 for cre, replacement in substitutions:
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
150 message = cre.sub(replacement, message)
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
151 # finally add links for issues
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
152 message = issue_re.sub(self._linkify_issue, message)
521
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
153 message = pullrequest_re.sub(self._linkify_pull_request, message)
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
154 return message
175
30b379cb68a1 Issue #249: Clear _count attributes out of various places.
martin.v.loewis
parents: 129
diff changeset
155
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
156 def _linkify_issue(self, match):
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
157 """Turn an issue (e.g. 'issue 1234' or '#1234') to an HTML link"""
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
158 template = ('<a class="%(status)s" title="[%(status)s] %(title)s" '
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
159 'href="issue%(issue_id)s">%(text)s</a>')
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
160 issue_id = match.group('id')
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
161 text = match.group('text')
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
162 cl = self._db.issue
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
163 # check if the issue exists
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
164 if not cl.hasnode(issue_id):
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
165 return text
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
166 # get the title
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
167 title = cgi.escape(cl.get(issue_id, 'title').replace('"', "'"))
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
168 status_id = cl.get(issue_id, 'status')
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
169 # get the name of the status
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
170 if status_id is not None:
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
171 status = self._db.status.get(status_id, 'name')
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
172 else:
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
173 status = 'none'
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
174 return template % dict(issue_id=issue_id, title=title,
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
175 status=status, text=text)
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
176
521
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
177 def _linkify_pull_request(self, match):
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
178 """Turn a pullrequest (e.g. 'PR 123') to an HTML link"""
534
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
179 template = ('<a href="%(base_url)s%(pr_no)s" %(cls)s'
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
180 'title="GitHub PR %(pr_no)s%(info)s">%(text)s</a>')
521
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
181 pr_no = match.group('pr_no')
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
182 text = match.group('text')
534
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
183 # find title and status
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
184 cl = self._db.pull_request
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
185 # find all the pull_request that refer to GitHub PR pr_no,
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
186 # with the most recently updated first
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
187 pr_ids = cl.filter(None, dict(number=pr_no), sort=[('-', 'activity')])
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
188 title = status = info = cls = ''
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
189 for pr_id in pr_ids:
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
190 if not title:
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
191 title = cl.get(pr_id, 'title', '')
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
192 if not status:
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
193 status = cl.get(pr_id, 'status', '')
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
194 if title and status:
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
195 # once we get both, escape and add to info
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
196 status = cgi.escape(status).replace('"', "'")
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
197 title = cgi.escape(title).replace('"', "'")
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
198 info = ': [%s] %s' % (status, title)
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
199 break
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
200 if status:
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
201 cls = 'class="%s" ' % ('open' if status == 'open' else 'closed')
522
1b16b4c8ab77 #587: simplify a function and add a couple more tests.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 521
diff changeset
202 base_url = 'https://github.com/python/cpython/pull/'
534
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
203 return template % dict(base_url=base_url, pr_no=pr_no, cls=cls,
38de93af8c3d #587: add PR title and status to PR links.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 533
diff changeset
204 info=info, text=text)
521
8708baeae844 #587: Convert PR references in messages to links. Initial patch by Anish Sshah.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 462
diff changeset
205
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
206
264
3cbcf5b9493d Fix a couple of XXX.
ezio.melotti
parents: 261
diff changeset
207 noise_changes = re.compile('(nosy_count|message_count)\: \d+\.0( -> \d+\.0)?')
175
30b379cb68a1 Issue #249: Clear _count attributes out of various places.
martin.v.loewis
parents: 129
diff changeset
208
30b379cb68a1 Issue #249: Clear _count attributes out of various places.
martin.v.loewis
parents: 129
diff changeset
209 def clean_count(history):
264
3cbcf5b9493d Fix a couple of XXX.
ezio.melotti
parents: 261
diff changeset
210 history = noise_changes.sub('', history).replace('<td><br />', '<td>')
175
30b379cb68a1 Issue #249: Clear _count attributes out of various places.
martin.v.loewis
parents: 129
diff changeset
211 return history
30b379cb68a1 Issue #249: Clear _count attributes out of various places.
martin.v.loewis
parents: 129
diff changeset
212
98
7b1482bfa197 Replace #<number> with a hyperlink to issue<number>, as proposed in
erik.forsberg
parents:
diff changeset
213 def init(instance):
260
6bc52d79bc0b #285: add a tooltip that shows status and title of linked issues on the tracker. Also avoid linking to unexisting issues.
ezio.melotti
parents: 240
diff changeset
214 register_propclass(hyperdb.String, PyDevStringHTMLProperty)
175
30b379cb68a1 Issue #249: Clear _count attributes out of various places.
martin.v.loewis
parents: 129
diff changeset
215 instance.registerUtil('clean_count', clean_count)