##// END OF EJS Templates
pull-requests: fixed multiple repetitions of referenced tickets in pull requests summary sidebar.
milka -
r4650:5d2569e3 default
parent child
Show More
@@ -25,6 +25,7 Consists of functions to typically be us
25 available to Controllers. This module is available to both as 'h'.
25 available to Controllers. This module is available to both as 'h'.
26 """
26 """
27 import base64
27 import base64
28 import collections
28
29
29 import os
30 import os
30 import random
31 import random
@@ -1733,7 +1734,7 def process_patterns(text_string, repo_n
1733
1734
1734
1735
1735 def urlify_commit_message(commit_text, repository=None, active_pattern_entries=None,
1736 def urlify_commit_message(commit_text, repository=None, active_pattern_entries=None,
1736 issues_container=None, error_container=None):
1737 issues_container_callback=None, error_container=None):
1737 """
1738 """
1738 Parses given text message and makes proper links.
1739 Parses given text message and makes proper links.
1739 issues are linked to given issue-server, and rest is a commit link
1740 issues are linked to given issue-server, and rest is a commit link
@@ -1756,8 +1757,9 def urlify_commit_message(commit_text, r
1756 new_text, issues, errors = process_patterns(
1757 new_text, issues, errors = process_patterns(
1757 new_text, repository or '', active_entries=active_pattern_entries)
1758 new_text, repository or '', active_entries=active_pattern_entries)
1758
1759
1759 if issues_container is not None:
1760 if issues_container_callback is not None:
1760 issues_container.extend(issues)
1761 for issue in issues:
1762 issues_container_callback(issue)
1761
1763
1762 if error_container is not None:
1764 if error_container is not None:
1763 error_container.extend(errors)
1765 error_container.extend(errors)
@@ -1802,7 +1804,7 def renderer_from_filename(filename, exc
1802
1804
1803
1805
1804 def render(source, renderer='rst', mentions=False, relative_urls=None,
1806 def render(source, renderer='rst', mentions=False, relative_urls=None,
1805 repo_name=None, active_pattern_entries=None, issues_container=None):
1807 repo_name=None, active_pattern_entries=None, issues_container_callback=None):
1806
1808
1807 def maybe_convert_relative_links(html_source):
1809 def maybe_convert_relative_links(html_source):
1808 if relative_urls:
1810 if relative_urls:
@@ -1819,8 +1821,9 def render(source, renderer='rst', menti
1819 source, issues, errors = process_patterns(
1821 source, issues, errors = process_patterns(
1820 source, repo_name, link_format='rst',
1822 source, repo_name, link_format='rst',
1821 active_entries=active_pattern_entries)
1823 active_entries=active_pattern_entries)
1822 if issues_container is not None:
1824 if issues_container_callback is not None:
1823 issues_container.extend(issues)
1825 for issue in issues:
1826 issues_container_callback(issue)
1824
1827
1825 return literal(
1828 return literal(
1826 '<div class="rst-block">%s</div>' %
1829 '<div class="rst-block">%s</div>' %
@@ -1833,8 +1836,10 def render(source, renderer='rst', menti
1833 source, issues, errors = process_patterns(
1836 source, issues, errors = process_patterns(
1834 source, repo_name, link_format='markdown',
1837 source, repo_name, link_format='markdown',
1835 active_entries=active_pattern_entries)
1838 active_entries=active_pattern_entries)
1836 if issues_container is not None:
1839 if issues_container_callback is not None:
1837 issues_container.extend(issues)
1840 for issue in issues:
1841 issues_container_callback(issue)
1842
1838
1843
1839 return literal(
1844 return literal(
1840 '<div class="markdown-block">%s</div>' %
1845 '<div class="markdown-block">%s</div>' %
@@ -2115,3 +2120,29 def is_active(menu_entry, selected):
2115
2120
2116 if selected in menu_entry:
2121 if selected in menu_entry:
2117 return "active"
2122 return "active"
2123
2124
2125 class IssuesRegistry(object):
2126 """
2127 issue_registry = IssuesRegistry()
2128 some_func(issues_callback=issues_registry(...))
2129 """
2130
2131 def __init__(self):
2132 self.issues = []
2133 self.unique_issues = collections.defaultdict(lambda: [])
2134
2135 def __call__(self, commit_dict=None):
2136 def callback(issue):
2137 if commit_dict and issue:
2138 issue['commit'] = commit_dict
2139 self.issues.append(issue)
2140 self.unique_issues[issue['id']].append(issue)
2141 return callback
2142
2143 def get_issues(self):
2144 return self.issues
2145
2146 @property
2147 def issues_unique_count(self):
2148 return len(set(i['id'] for i in self.issues))
@@ -24,7 +24,7
24 ## to speed up lookups cache some functions before the loop
24 ## to speed up lookups cache some functions before the loop
25 <%
25 <%
26 active_patterns = h.get_active_pattern_entries(c.repo_name)
26 active_patterns = h.get_active_pattern_entries(c.repo_name)
27 urlify_commit_message = h.partial(h.urlify_commit_message, active_pattern_entries=active_patterns, issues_container=getattr(c, 'referenced_commit_issues', None))
27 urlify_commit_message = h.partial(h.urlify_commit_message, active_pattern_entries=active_patterns)
28 %>
28 %>
29
29
30 %for commit in c.commit_ranges:
30 %for commit in c.commit_ranges:
@@ -57,7 +57,7
57 </td>
57 </td>
58 <td class="mid td-description">
58 <td class="mid td-description">
59 <div class="log-container truncate-wrap">
59 <div class="log-container truncate-wrap">
60 <div class="message truncate" id="c-${commit.raw_id}" data-message-raw="${commit.message}">${urlify_commit_message(commit.message, c.repo_name)}</div>
60 <div class="message truncate" id="c-${commit.raw_id}" data-message-raw="${commit.message}">${urlify_commit_message(commit.message, c.repo_name, issues_container_callback=getattr(c, 'referenced_commit_issues', lambda p:p)(commit.serialize()))}</div>
61 </div>
61 </div>
62 </td>
62 </td>
63 </tr>
63 </tr>
@@ -27,8 +27,8
27 <%def name="main()">
27 <%def name="main()">
28 ## Container to gather extracted Tickets
28 ## Container to gather extracted Tickets
29 <%
29 <%
30 c.referenced_commit_issues = []
30 c.referenced_commit_issues = h.IssuesRegistry()
31 c.referenced_desc_issues = []
31 c.referenced_desc_issues = h.IssuesRegistry()
32 %>
32 %>
33
33
34 <script type="text/javascript">
34 <script type="text/javascript">
@@ -86,7 +86,7
86 </div>
86 </div>
87
87
88 <div id="pr-desc" class="input" title="${_('Rendered using {} renderer').format(c.renderer)}">
88 <div id="pr-desc" class="input" title="${_('Rendered using {} renderer').format(c.renderer)}">
89 ${h.render(c.pull_request.description, renderer=c.renderer, repo_name=c.repo_name, issues_container=c.referenced_desc_issues)}
89 ${h.render(c.pull_request.description, renderer=c.renderer, repo_name=c.repo_name, issues_container_callback=c.referenced_desc_issues())}
90 </div>
90 </div>
91
91
92 <div id="pr-desc-edit" class="input textarea" style="display: none;">
92 <div id="pr-desc-edit" class="input textarea" style="display: none;">
@@ -435,7 +435,7
435 </td>
435 </td>
436 <td class="mid td-description">
436 <td class="mid td-description">
437 <div class="log-container truncate-wrap">
437 <div class="log-container truncate-wrap">
438 <div class="message truncate" id="c-${commit.raw_id}" data-message-raw="${commit.message}">${h.urlify_commit_message(commit.message, c.repo_name, issues_container=c.referenced_commit_issues)}</div>
438 <div class="message truncate" id="c-${commit.raw_id}" data-message-raw="${commit.message}">${h.urlify_commit_message(commit.message, c.repo_name, issues_container_callback=c.referenced_commit_issues(commit.serialize()))}</div>
439 </div>
439 </div>
440 </td>
440 </td>
441 </tr>
441 </tr>
@@ -809,7 +809,7
809 <div class="sidebar-element clear-both">
809 <div class="sidebar-element clear-both">
810 <div class="tooltip right-sidebar-collapsed-state" style="display: none" onclick="toggleSidebar(); return false" title="${_('Referenced Tickets')}">
810 <div class="tooltip right-sidebar-collapsed-state" style="display: none" onclick="toggleSidebar(); return false" title="${_('Referenced Tickets')}">
811 <i class="icon-info-circled"></i>
811 <i class="icon-info-circled"></i>
812 ${(len(c.referenced_desc_issues) + len(c.referenced_commit_issues))}
812 ${(c.referenced_desc_issues.issues_unique_count + c.referenced_commit_issues.issues_unique_count)}
813 </div>
813 </div>
814
814
815 <div class="right-sidebar-expanded-state pr-details-title">
815 <div class="right-sidebar-expanded-state pr-details-title">
@@ -822,15 +822,17
822 <table>
822 <table>
823
823
824 <tr><td><code>${_('In pull request description')}:</code></td></tr>
824 <tr><td><code>${_('In pull request description')}:</code></td></tr>
825 % if c.referenced_desc_issues:
825 % if c.referenced_desc_issues.issues:
826 % for ticket_dict in sorted(c.referenced_desc_issues):
826
827 % for ticket_id, ticket_dict in c.referenced_desc_issues.unique_issues.items():
827 <tr>
828 <tr>
828 <td>
829 <td>
829 <a href="${ticket_dict.get('url')}">
830 <a href="${ticket_dict[0].get('url')}">
830 ${ticket_dict.get('id')}
831 ${ticket_id}
831 </a>
832 </a>
832 </td>
833 </td>
833 </tr>
834 </tr>
835
834 % endfor
836 % endfor
835 % else:
837 % else:
836 <tr>
838 <tr>
@@ -841,13 +843,14
841 % endif
843 % endif
842
844
843 <tr><td style="padding-top: 10px"><code>${_('In commit messages')}:</code></td></tr>
845 <tr><td style="padding-top: 10px"><code>${_('In commit messages')}:</code></td></tr>
844 % if c.referenced_commit_issues:
846 % if c.referenced_commit_issues.issues:
845 % for ticket_dict in sorted(c.referenced_commit_issues):
847 % for ticket_id, ticket_dict in c.referenced_commit_issues.unique_issues.items():
846 <tr>
848 <tr>
847 <td>
849 <td>
848 <a href="${ticket_dict.get('url')}">
850 <a href="${ticket_dict[0].get('url')}">
849 ${ticket_dict.get('id')}
851 ${ticket_id}
850 </a>
852 </a>
853 - ${_ungettext('in %s commit', 'in %s commits', len(ticket_dict)) % (len(ticket_dict))}
851 </td>
854 </td>
852 </tr>
855 </tr>
853 % endfor
856 % endfor
General Comments 0
You need to be logged in to leave comments. Login now