diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -25,6 +25,7 @@ Consists of functions to typically be us available to Controllers. This module is available to both as 'h'. """ import base64 +import collections import os import random @@ -1733,7 +1734,7 @@ def process_patterns(text_string, repo_n def urlify_commit_message(commit_text, repository=None, active_pattern_entries=None, - issues_container=None, error_container=None): + issues_container_callback=None, error_container=None): """ Parses given text message and makes proper links. issues are linked to given issue-server, and rest is a commit link @@ -1756,8 +1757,9 @@ def urlify_commit_message(commit_text, r new_text, issues, errors = process_patterns( new_text, repository or '', active_entries=active_pattern_entries) - if issues_container is not None: - issues_container.extend(issues) + if issues_container_callback is not None: + for issue in issues: + issues_container_callback(issue) if error_container is not None: error_container.extend(errors) @@ -1802,7 +1804,7 @@ def renderer_from_filename(filename, exc def render(source, renderer='rst', mentions=False, relative_urls=None, - repo_name=None, active_pattern_entries=None, issues_container=None): + repo_name=None, active_pattern_entries=None, issues_container_callback=None): def maybe_convert_relative_links(html_source): if relative_urls: @@ -1819,8 +1821,9 @@ def render(source, renderer='rst', menti source, issues, errors = process_patterns( source, repo_name, link_format='rst', active_entries=active_pattern_entries) - if issues_container is not None: - issues_container.extend(issues) + if issues_container_callback is not None: + for issue in issues: + issues_container_callback(issue) return literal( '
%s
' % @@ -1833,8 +1836,10 @@ def render(source, renderer='rst', menti source, issues, errors = process_patterns( source, repo_name, link_format='markdown', active_entries=active_pattern_entries) - if issues_container is not None: - issues_container.extend(issues) + if issues_container_callback is not None: + for issue in issues: + issues_container_callback(issue) + return literal( '
%s
' % @@ -2115,3 +2120,29 @@ def is_active(menu_entry, selected): if selected in menu_entry: return "active" + + +class IssuesRegistry(object): + """ + issue_registry = IssuesRegistry() + some_func(issues_callback=issues_registry(...)) + """ + + def __init__(self): + self.issues = [] + self.unique_issues = collections.defaultdict(lambda: []) + + def __call__(self, commit_dict=None): + def callback(issue): + if commit_dict and issue: + issue['commit'] = commit_dict + self.issues.append(issue) + self.unique_issues[issue['id']].append(issue) + return callback + + def get_issues(self): + return self.issues + + @property + def issues_unique_count(self): + return len(set(i['id'] for i in self.issues)) diff --git a/rhodecode/templates/compare/compare_commits.mako b/rhodecode/templates/compare/compare_commits.mako --- a/rhodecode/templates/compare/compare_commits.mako +++ b/rhodecode/templates/compare/compare_commits.mako @@ -24,7 +24,7 @@ ## to speed up lookups cache some functions before the loop <% active_patterns = h.get_active_pattern_entries(c.repo_name) - urlify_commit_message = h.partial(h.urlify_commit_message, active_pattern_entries=active_patterns, issues_container=getattr(c, 'referenced_commit_issues', None)) + urlify_commit_message = h.partial(h.urlify_commit_message, active_pattern_entries=active_patterns) %> %for commit in c.commit_ranges: @@ -57,7 +57,7 @@
-
${urlify_commit_message(commit.message, c.repo_name)}
+
${urlify_commit_message(commit.message, c.repo_name, issues_container_callback=getattr(c, 'referenced_commit_issues', lambda p:p)(commit.serialize()))}
diff --git a/rhodecode/templates/pullrequests/pullrequest_show.mako b/rhodecode/templates/pullrequests/pullrequest_show.mako --- a/rhodecode/templates/pullrequests/pullrequest_show.mako +++ b/rhodecode/templates/pullrequests/pullrequest_show.mako @@ -27,8 +27,8 @@ <%def name="main()"> ## Container to gather extracted Tickets <% - c.referenced_commit_issues = [] - c.referenced_desc_issues = [] + c.referenced_commit_issues = h.IssuesRegistry() + c.referenced_desc_issues = h.IssuesRegistry() %>