|
3 | 3 | from trac.core import *
|
4 | 4 | from trac.web.chrome import INavigationContributor, ITemplateProvider, add_script, add_script_data, add_stylesheet, add_notice, add_link
|
5 | 5 | from trac.web.main import IRequestHandler, IRequestFilter
|
| 6 | +from trac.web.api import ITemplateStreamFilter |
6 | 7 | from trac.util import Markup
|
7 | 8 | from trac.util.text import to_unicode
|
8 | 9 | from trac.util.presentation import Paginator
|
9 | 10 | from trac.versioncontrol.api import RepositoryManager
|
| 11 | +from genshi.filters import Transformer |
10 | 12 | from code_comments.comments import Comments
|
11 | 13 | from code_comments.comment import CommentJSONEncoder, format_to_html
|
12 | 14 |
|
@@ -290,3 +292,28 @@ def match_request(self, req):
|
290 | 292 |
|
291 | 293 | def process_request(self, req):
|
292 | 294 | req.send(format_to_html(req, self.env, req.args.get('text', '')).encode('utf-8'))
|
| 295 | + |
| 296 | +class HighlightCommentedRevisions(Component): |
| 297 | + implements(ITemplateStreamFilter) |
| 298 | + |
| 299 | + def filter_stream(self, req, method, filename, stream, data): |
| 300 | + if re.match(r'^\/log\/\w+', req.path_info): |
| 301 | + filter = Transformer('//a[@class="chgset"]') |
| 302 | + stream |= filter.attr("class", lambda name, event: self.addCssClassIfCommented(name, event)) |
| 303 | + self.env.log.info(str(data)) |
| 304 | + return stream |
| 305 | + |
| 306 | + def addCssClassIfCommented(self, name, event): |
| 307 | + attrs = event[1][1] |
| 308 | + link = attrs.get('href') |
| 309 | + match = re.match(r'^\/changeset\/([^\/]+)\/([^\/\?\#]+)', link) |
| 310 | + if match: |
| 311 | + query_params = {} |
| 312 | + query_params['type'] = 'changeset' |
| 313 | + query_params['revision'] = match.group(1) |
| 314 | + query_params['reponame'] = match.group(2) |
| 315 | + count = Comments(None, self.env).count(query_params) |
| 316 | + return attrs.get(name) + (" chgset-commented" if (count > 0) else "") |
| 317 | + else: |
| 318 | + # Should not happen, link contained no revision-id |
| 319 | + return attrs.get(name) |
0 commit comments