##// END OF EJS Templates
issue-tracker: cache active patterns in the template so we can re-use them when rendering comments....
bart -
r4202:5286ca08 stable
parent child Browse files
Show More
@@ -1522,7 +1522,10 b' def process_patterns(text_string, repo_n'
1522 1522 raise ValueError('Link format can be only one of:{} got {}'.format(
1523 1523 allowed_formats, link_format))
1524 1524
1525 active_entries = active_entries or get_active_pattern_entries(repo_name)
1525 if active_entries is None:
1526 log.debug('Fetch active patterns for repo: %s', repo_name)
1527 active_entries = get_active_pattern_entries(repo_name)
1528
1526 1529 issues_data = []
1527 1530 new_text = text_string
1528 1531
@@ -1580,6 +1583,7 b' def urlify_commit_message(commit_text, r'
1580 1583 Parses given text message and makes proper links.
1581 1584 issues are linked to given issue-server, and rest is a commit link
1582 1585 """
1586
1583 1587 def escaper(_text):
1584 1588 return _text.replace('<', '&lt;').replace('>', '&gt;')
1585 1589
@@ -1636,7 +1640,7 b' def renderer_from_filename(filename, exc'
1636 1640
1637 1641
1638 1642 def render(source, renderer='rst', mentions=False, relative_urls=None,
1639 repo_name=None):
1643 repo_name=None, active_pattern_entries=None):
1640 1644
1641 1645 def maybe_convert_relative_links(html_source):
1642 1646 if relative_urls:
@@ -1651,7 +1655,8 b" def render(source, renderer='rst', menti"
1651 1655 if repo_name:
1652 1656 # process patterns on comments if we pass in repo name
1653 1657 source, issues = process_patterns(
1654 source, repo_name, link_format='rst')
1658 source, repo_name, link_format='rst',
1659 active_entries=active_pattern_entries)
1655 1660
1656 1661 return literal(
1657 1662 '<div class="rst-block">%s</div>' %
@@ -1662,7 +1667,8 b" def render(source, renderer='rst', menti"
1662 1667 if repo_name:
1663 1668 # process patterns on comments if we pass in repo name
1664 1669 source, issues = process_patterns(
1665 source, repo_name, link_format='markdown')
1670 source, repo_name, link_format='markdown',
1671 active_entries=active_pattern_entries)
1666 1672
1667 1673 return literal(
1668 1674 '<div class="markdown-block">%s</div>' %
@@ -5,7 +5,7 b''
5 5 ##
6 6 <%namespace name="base" file="/base/base.mako"/>
7 7
8 <%def name="comment_block(comment, inline=False)">
8 <%def name="comment_block(comment, inline=False, active_pattern_entries=None)">
9 9 <% pr_index_ver = comment.get_index_version(getattr(c, 'versions', [])) %>
10 10 <% latest_ver = len(getattr(c, 'versions', [])) %>
11 11 % if inline:
@@ -156,7 +156,7 b''
156 156 </div>
157 157 </div>
158 158 <div class="text">
159 ${h.render(comment.text, renderer=comment.renderer, mentions=True, repo_name=getattr(c, 'repo_name', None))}
159 ${h.render(comment.text, renderer=comment.renderer, mentions=True, repo_name=getattr(c, 'repo_name', None), active_pattern_entries=active_pattern_entries)}
160 160 </div>
161 161
162 162 </div>
@@ -164,13 +164,17 b''
164 164
165 165 ## generate main comments
166 166 <%def name="generate_comments(comments, include_pull_request=False, is_pull_request=False)">
167 <%
168 active_pattern_entries = h.get_active_pattern_entries(getattr(c, 'repo_name', None))
169 %>
170
167 171 <div class="general-comments" id="comments">
168 172 %for comment in comments:
169 173 <div id="comment-tr-${comment.comment_id}">
170 174 ## only render comments that are not from pull request, or from
171 175 ## pull request and a status change
172 176 %if not comment.pull_request or (comment.pull_request and comment.status_change) or include_pull_request:
173 ${comment_block(comment)}
177 ${comment_block(comment, active_pattern_entries=active_pattern_entries)}
174 178 %endif
175 179 </div>
176 180 %endfor
@@ -60,12 +60,16 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
60 60 <%
61 61 diffset_container_id = h.md5(diffset.target_ref)
62 62 collapse_all = len(diffset.files) > collapse_when_files_over
63 active_pattern_entries = h.get_active_pattern_entries(getattr(c, 'repo_name', None))
63 64 %>
64 65
65 66 %if use_comments:
67
68 ## Template for injecting comments
66 69 <div id="cb-comments-inline-container-template" class="js-template">
67 ${inline_comments_container([], inline_comments)}
70 ${inline_comments_container([])}
68 71 </div>
72
69 73 <div class="js-template" id="cb-comment-inline-form-template">
70 74 <div class="comment-inline-form ac">
71 75
@@ -259,7 +263,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
259 263 ## new/deleted/empty content case
260 264 % if not filediff.hunks:
261 265 ## Comment container, on "fakes" hunk that contains all data to render comments
262 ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], filediff.hunk_ops, use_comments=use_comments, inline_comments=inline_comments)}
266 ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], filediff.hunk_ops, use_comments=use_comments, inline_comments=inline_comments, active_pattern_entries=active_pattern_entries)}
263 267 % endif
264 268
265 269 %if filediff.limited_diff:
@@ -299,7 +303,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
299 303 ${hunk.section_header}
300 304 </td>
301 305 </tr>
302 ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], hunk, use_comments=use_comments, inline_comments=inline_comments)}
306 ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], hunk, use_comments=use_comments, inline_comments=inline_comments, active_pattern_entries=active_pattern_entries)}
303 307 % endfor
304 308
305 309 <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %>
@@ -323,7 +327,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
323 327 <td class="cb-lineno cb-context"></td>
324 328 <td class="cb-lineno cb-context"></td>
325 329 <td class="cb-content cb-context">
326 ${inline_comments_container(comments, inline_comments)}
330 ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)}
327 331 </td>
328 332 </tr>
329 333 %elif c.user_session_attrs["diffmode"] == 'sideside':
@@ -348,7 +352,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
348 352 <td class="cb-lineno cb-context"></td>
349 353 <td class="cb-content cb-context">
350 354 % if lineno.startswith('o'):
351 ${inline_comments_container(comments, inline_comments)}
355 ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)}
352 356 % endif
353 357 </td>
354 358
@@ -356,7 +360,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
356 360 <td class="cb-lineno cb-context"></td>
357 361 <td class="cb-content cb-context">
358 362 % if lineno.startswith('n'):
359 ${inline_comments_container(comments, inline_comments)}
363 ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)}
360 364 % endif
361 365 </td>
362 366 </tr>
@@ -415,7 +419,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
415 419 <td class="cb-lineno cb-context"></td>
416 420 <td class="cb-lineno cb-context"></td>
417 421 <td class="cb-content cb-context">
418 ${inline_comments_container(comments_dict['comments'], inline_comments)}
422 ${inline_comments_container(comments_dict['comments'], active_pattern_entries=active_pattern_entries)}
419 423 </td>
420 424 </tr>
421 425 %elif c.user_session_attrs["diffmode"] == 'sideside':
@@ -427,7 +431,7 b" return '%s_%s_%i' % (h.md5_safe(commit+f"
427 431 <td class="cb-data cb-context"></td>
428 432 <td class="cb-lineno cb-context"></td>
429 433 <td class="cb-content cb-context">
430 ${inline_comments_container(comments_dict['comments'], inline_comments)}
434 ${inline_comments_container(comments_dict['comments'], active_pattern_entries=active_pattern_entries)}
431 435 </td>
432 436 </tr>
433 437 %endif
@@ -584,10 +588,11 b' from rhodecode.lib.diffs import NEW_FILE'
584 588 </%def>
585 589
586 590
587 <%def name="inline_comments_container(comments, inline_comments)">
591 <%def name="inline_comments_container(comments, active_pattern_entries=None)">
592
588 593 <div class="inline-comments">
589 594 %for comment in comments:
590 ${commentblock.comment_block(comment, inline=True)}
595 ${commentblock.comment_block(comment, inline=True, active_pattern_entries=active_pattern_entries)}
591 596 %endfor
592 597 % if comments and comments[-1].outdated:
593 598 <span class="btn btn-secondary cb-comment-add-button comment-outdated}" style="display: none;}">
@@ -619,7 +624,7 b' def get_comments_for(diff_type, comments'
619 624 return data
620 625 %>
621 626
622 <%def name="render_hunk_lines_sideside(filediff, hunk, use_comments=False, inline_comments=None)">
627 <%def name="render_hunk_lines_sideside(filediff, hunk, use_comments=False, inline_comments=None, active_pattern_entries=None)">
623 628 %for i, line in enumerate(hunk.sideside):
624 629 <%
625 630 old_line_anchor, new_line_anchor = None, None
@@ -669,7 +674,7 b' def get_comments_for(diff_type, comments'
669 674 <span class="cb-code"><span class="cb-action ${action_class(line.original.action)}"></span>${line.original.content or '' | n}</span>
670 675
671 676 %if use_comments and line.original.lineno and line_old_comments:
672 ${inline_comments_container(line_old_comments, inline_comments)}
677 ${inline_comments_container(line_old_comments, active_pattern_entries=active_pattern_entries)}
673 678 %endif
674 679
675 680 </td>
@@ -711,7 +716,7 b' def get_comments_for(diff_type, comments'
711 716 %endif
712 717 <span class="cb-code"><span class="cb-action ${action_class(line.modified.action)}"></span>${line.modified.content or '' | n}</span>
713 718 %if use_comments and line.modified.lineno and line_new_comments:
714 ${inline_comments_container(line_new_comments, inline_comments)}
719 ${inline_comments_container(line_new_comments, active_pattern_entries=active_pattern_entries)}
715 720 %endif
716 721 </td>
717 722 </tr>
@@ -719,7 +724,7 b' def get_comments_for(diff_type, comments'
719 724 </%def>
720 725
721 726
722 <%def name="render_hunk_lines_unified(filediff, hunk, use_comments=False, inline_comments=None)">
727 <%def name="render_hunk_lines_unified(filediff, hunk, use_comments=False, inline_comments=None, active_pattern_entries=None)">
723 728 %for old_line_no, new_line_no, action, content, comments_args in hunk.unified:
724 729
725 730 <%
@@ -777,7 +782,7 b' def get_comments_for(diff_type, comments'
777 782 %endif
778 783 <span class="cb-code"><span class="cb-action ${action_class(action)}"></span> ${content or '' | n}</span>
779 784 %if use_comments and comments:
780 ${inline_comments_container(comments, inline_comments)}
785 ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)}
781 786 %endif
782 787 </td>
783 788 </tr>
@@ -785,11 +790,11 b' def get_comments_for(diff_type, comments'
785 790 </%def>
786 791
787 792
788 <%def name="render_hunk_lines(filediff, diff_mode, hunk, use_comments, inline_comments)">
793 <%def name="render_hunk_lines(filediff, diff_mode, hunk, use_comments, inline_comments, active_pattern_entries)">
789 794 % if diff_mode == 'unified':
790 ${render_hunk_lines_unified(filediff, hunk, use_comments=use_comments, inline_comments=inline_comments)}
795 ${render_hunk_lines_unified(filediff, hunk, use_comments=use_comments, inline_comments=inline_comments, active_pattern_entries=active_pattern_entries)}
791 796 % elif diff_mode == 'sideside':
792 ${render_hunk_lines_sideside(filediff, hunk, use_comments=use_comments, inline_comments=inline_comments)}
797 ${render_hunk_lines_sideside(filediff, hunk, use_comments=use_comments, inline_comments=inline_comments, active_pattern_entries=active_pattern_entries)}
793 798 % else:
794 799 <tr class="cb-line">
795 800 <td>unknown diff mode</td>
General Comments 0
You need to be logged in to leave comments. Login now