|
5 | 5 | import re
|
6 | 6 |
|
7 | 7 | from trac.core import Component, implements
|
| 8 | +from trac.web.api import ITemplateStreamFilter |
8 | 9 | from trac.util import Markup
|
9 | 10 | from trac.util.presentation import Paginator
|
10 | 11 | from trac.util.text import to_unicode
|
|
13 | 14 | Chrome, INavigationContributor, ITemplateProvider, add_link, add_notice,
|
14 | 15 | add_script, add_script_data, add_stylesheet)
|
15 | 16 | from trac.web.main import IRequestHandler, IRequestFilter
|
| 17 | +from genshi.filters import Transformer |
16 | 18 |
|
17 | 19 | from code_comments.comments import Comments
|
18 | 20 | from code_comments.comment import CommentJSONEncoder, format_to_html
|
@@ -351,3 +353,28 @@ def match_request(self, req):
|
351 | 353 | def process_request(self, req):
|
352 | 354 | html = format_to_html(req, self.env, req.args.get('text', ''))
|
353 | 355 | req.send(html.encode('utf-8'))
|
| 356 | + |
| 357 | +class HighlightCommentedRevisions(Component): |
| 358 | + implements(ITemplateStreamFilter) |
| 359 | + |
| 360 | + def filter_stream(self, req, method, filename, stream, data): |
| 361 | + if re.match(r'^\/log\/\w+', req.path_info): |
| 362 | + filter = Transformer('//a[@class="chgset"]') |
| 363 | + stream |= filter.attr("class", lambda name, event: self.addCssClassIfCommented(name, event)) |
| 364 | + self.env.log.info(str(data)) |
| 365 | + return stream |
| 366 | + |
| 367 | + def addCssClassIfCommented(self, name, event): |
| 368 | + attrs = event[1][1] |
| 369 | + link = attrs.get('href') |
| 370 | + match = re.match(r'^\/changeset\/([^\/]+)\/([^\/\?\#]+)', link) |
| 371 | + if match: |
| 372 | + query_params = {} |
| 373 | + query_params['type'] = 'changeset' |
| 374 | + query_params['revision'] = match.group(1) |
| 375 | + query_params['reponame'] = match.group(2) |
| 376 | + count = Comments(None, self.env).count(query_params) |
| 377 | + return attrs.get(name) + (" chgset-commented" if (count > 0) else "") |
| 378 | + else: |
| 379 | + # Should not happen, link contained no revision-id |
| 380 | + return attrs.get(name) |
0 commit comments