issue-tracker: cache active patterns in the template so we can re-use them when rendering comments....
bart -
r4202:5286ca08 stable
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -1522,7 +1522,10
1522 raise ValueError('Link format can be only one of:{} got {}'.format(
1522 raise ValueError('Link format can be only one of:{} got {}'.format(
1523 allowed_formats, link_format))
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 issues_data = []
1529 issues_data = []
1527 new_text = text_string
1530 new_text = text_string
1528
1531
@@ -1580,6 +1583,7
1580 Parses given text message and makes proper links.
1583 Parses given text message and makes proper links.
1581 issues are linked to given issue-server, and rest is a commit link
1584 issues are linked to given issue-server, and rest is a commit link
1582 """
1585 """
1586
1583 def escaper(_text):
1587 def escaper(_text):
1584 return _text.replace('<', '&lt;').replace('>', '&gt;')
1588 return _text.replace('<', '&lt;').replace('>', '&gt;')
1585
1589
@@ -1636,7 +1640,7
1636
1640
1637
1641
1638 def render(source, renderer='rst', mentions=False, relative_urls=None,
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 def maybe_convert_relative_links(html_source):
1645 def maybe_convert_relative_links(html_source):
1642 if relative_urls:
1646 if relative_urls:
@@ -1651,7 +1655,8
1651 if repo_name:
1655 if repo_name:
1652 # process patterns on comments if we pass in repo name
1656 # process patterns on comments if we pass in repo name
1653 source, issues = process_patterns(
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 return literal(
1661 return literal(
1657 '<div class="rst-block">%s</div>' %
1662 '<div class="rst-block">%s</div>' %
@@ -1662,7 +1667,8
1662 if repo_name:
1667 if repo_name:
1663 # process patterns on comments if we pass in repo name
1668 # process patterns on comments if we pass in repo name
1664 source, issues = process_patterns(
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 return literal(
1673 return literal(
1668 '<div class="markdown-block">%s</div>' %
1674 '<div class="markdown-block">%s</div>' %
@@ -5,7 +5,7
5 ##
5 ##
6 <%namespace name="base" file="/base/base.mako"/>
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 <% pr_index_ver = comment.get_index_version(getattr(c, 'versions', [])) %>
9 <% pr_index_ver = comment.get_index_version(getattr(c, 'versions', [])) %>
10 <% latest_ver = len(getattr(c, 'versions', [])) %>
10 <% latest_ver = len(getattr(c, 'versions', [])) %>
11 % if inline:
11 % if inline:
@@ -156,7 +156,7
156 </div>
156 </div>
157 </div>
157 </div>
158 <div class="text">
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 </div>
160 </div>
161
161
162 </div>
162 </div>
@@ -164,13 +164,17
164
164
165 ## generate main comments
165 ## generate main comments
166 <%def name="generate_comments(comments, include_pull_request=False, is_pull_request=False)">
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 <div class="general-comments" id="comments">
171 <div class="general-comments" id="comments">
168 %for comment in comments:
172 %for comment in comments:
169 <div id="comment-tr-${comment.comment_id}">
173 <div id="comment-tr-${comment.comment_id}">
170 ## only render comments that are not from pull request, or from
174 ## only render comments that are not from pull request, or from
171 ## pull request and a status change
175 ## pull request and a status change
172 %if not comment.pull_request or (comment.pull_request and comment.status_change) or include_pull_request:
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 %endif
178 %endif
175 </div>
179 </div>
176 %endfor
180 %endfor
@@ -60,12 +60,16
60 <%
60 <%
61 diffset_container_id = h.md5(diffset.target_ref)
61 diffset_container_id = h.md5(diffset.target_ref)
62 collapse_all = len(diffset.files) > collapse_when_files_over
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 %if use_comments:
66 %if use_comments:
67
68 ## Template for injecting comments
66 <div id="cb-comments-inline-container-template" class="js-template">
69 <div id="cb-comments-inline-container-template" class="js-template">
67 ${inline_comments_container([], inline_comments)}
70 ${inline_comments_container([])}
68 </div>
71 </div>
72
69 <div class="js-template" id="cb-comment-inline-form-template">
73 <div class="js-template" id="cb-comment-inline-form-template">
70 <div class="comment-inline-form ac">
74 <div class="comment-inline-form ac">
71
75
@@ -259,7 +263,7
259 ## new/deleted/empty content case
263 ## new/deleted/empty content case
260 % if not filediff.hunks:
264 % if not filediff.hunks:
261 ## Comment container, on "fakes" hunk that contains all data to render comments
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 % endif
267 % endif
264
268
265 %if filediff.limited_diff:
269 %if filediff.limited_diff:
@@ -299,7 +303,7
299 ${hunk.section_header}
303 ${hunk.section_header}
300 </td>
304 </td>
301 </tr>
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 % endfor
307 % endfor
304
308
305 <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %>
309 <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %>
@@ -323,7 +327,7
323 <td class="cb-lineno cb-context"></td>
327 <td class="cb-lineno cb-context"></td>
324 <td class="cb-lineno cb-context"></td>
328 <td class="cb-lineno cb-context"></td>
325 <td class="cb-content cb-context">
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 </td>
331 </td>
328 </tr>
332 </tr>
329 %elif c.user_session_attrs["diffmode"] == 'sideside':
333 %elif c.user_session_attrs["diffmode"] == 'sideside':
@@ -348,7 +352,7
348 <td class="cb-lineno cb-context"></td>
352 <td class="cb-lineno cb-context"></td>
349 <td class="cb-content cb-context">
353 <td class="cb-content cb-context">
350 % if lineno.startswith('o'):
354 % if lineno.startswith('o'):
351 ${inline_comments_container(comments, inline_comments)}
355 ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)}
352 % endif
356 % endif
353 </td>
357 </td>
354
358
@@ -356,7 +360,7
356 <td class="cb-lineno cb-context"></td>
360 <td class="cb-lineno cb-context"></td>
357 <td class="cb-content cb-context">
361 <td class="cb-content cb-context">
358 % if lineno.startswith('n'):
362 % if lineno.startswith('n'):
359 ${inline_comments_container(comments, inline_comments)}
363 ${inline_comments_container(comments, active_pattern_entries=active_pattern_entries)}
360 % endif
364 % endif
361 </td>
365 </td>
362 </tr>
366 </tr>
@@ -415,7 +419,7
415 <td class="cb-lineno cb-context"></td>
419 <td class="cb-lineno cb-context"></td>
416 <td class="cb-lineno cb-context"></td>
420 <td class="cb-lineno cb-context"></td>
417 <td class="cb-content cb-context">
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 </td>
423 </td>
420 </tr>
424 </tr>
421 %elif c.user_session_attrs["diffmode"] == 'sideside':
425 %elif c.user_session_attrs["diffmode"] == 'sideside':
@@ -427,7 +431,7
427 <td class="cb-data cb-context"></td>
431 <td class="cb-data cb-context"></td>
428 <td class="cb-lineno cb-context"></td>
432 <td class="cb-lineno cb-context"></td>
429 <td class="cb-content cb-context">
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 </td>
435 </td>
432 </tr>
436 </tr>
433 %endif
437 %endif
@@ -584,10 +588,11
584 </%def>
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 <div class="inline-comments">
593 <div class="inline-comments">
589 %for comment in comments:
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 %endfor
596 %endfor
592 % if comments and comments[-1].outdated:
597 % if comments and comments[-1].outdated:
593 <span class="btn btn-secondary cb-comment-add-button comment-outdated}" style="display: none;}">
598 <span class="btn btn-secondary cb-comment-add-button comment-outdated}" style="display: none;}">
@@ -619,7 +624,7
619 return data
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 %for i, line in enumerate(hunk.sideside):
628 %for i, line in enumerate(hunk.sideside):
624 <%
629 <%
625 old_line_anchor, new_line_anchor = None, None
630 old_line_anchor, new_line_anchor = None, None
@@ -669,7 +674,7
669 <span class="cb-code"><span class="cb-action ${action_class(line.original.action)}"></span>${line.original.content or '' | n}</span>
674 <span class="cb-code"><span class="cb-action ${action_class(line.original.action)}"></span>${line.original.content or '' | n}</span>
670
675
671 %if use_comments and line.original.lineno and line_old_comments:
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 %endif
678 %endif
674
679
675 </td>
680 </td>
@@ -711,7 +716,7
711 %endif
716 %endif
712 <span class="cb-code"><span class="cb-action ${action_class(line.modified.action)}"></span>${line.modified.content or '' | n}</span>
717 <span class="cb-code"><span class="cb-action ${action_class(line.modified.action)}"></span>${line.modified.content or '' | n}</span>
713 %if use_comments and line.modified.lineno and line_new_comments:
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 %endif
720 %endif
716 </td>
721 </td>
717 </tr>
722 </tr>
@@ -719,7 +724,7
719 </%def>
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 %for old_line_no, new_line_no, action, content, comments_args in hunk.unified:
728 %for old_line_no, new_line_no, action, content, comments_args in hunk.unified:
724
729
725 <%
730 <%
@@ -777,7 +782,7
777 %endif
782 %endif
778 <span class="cb-code"><span class="cb-action ${action_class(action)}"></span> ${content or '' | n}</span>
783 <span class="cb-code"><span class="cb-action ${action_class(action)}"></span> ${content or '' | n}</span>
779 %if use_comments and comments:
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 %endif
786 %endif
782 </td>
787 </td>
783 </tr>
788 </tr>
@@ -785,11 +790,11
785 </%def>
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 % if diff_mode == 'unified':
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 % elif diff_mode == 'sideside':
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 % else:
798 % else:
794 <tr class="cb-line">
799 <tr class="cb-line">
795 <td>unknown diff mode</td>
800 <td>unknown diff mode</td>
Comments 0
You need to be logged in to leave comments. Login now