Changeset - 6d9b3ade3051
[Not reviewed]
beta
0 1 0
Zachary Auclair - 13 years ago 2012-09-21 02:30:55
zach101@gmail.com
Allowing multiple issue servers to be autolinked in the changeset view;
linking is now contingent on issue_server_link, issue_pat and issue_prefix
being defined; multiple servers can be used by specifying a common suffix on all
the above variables, ie ..

issue_server_link_1
issue_pat_1
issue_prefix_1

.. and ..

issue_server_link_other
issue_pat_other
issue_prefix_other

.. would be treated as two distinct servers, but ..

issue_pat_thing

.. would be ignored (since the other two requisite vars aren't present).

This patch is backwards compatible with existing variables (as a suffix
isn't needed).
1 file changed with 23 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/helpers.py
Show inline comments
 
@@ -991,72 +991,88 @@ def urlify_commit(text_, repository=None
 
    def linkify_others(t, l):
 
        urls = re.compile(r'(\<a.*?\<\/a\>)',)
 
        links = []
 
        for e in urls.split(t):
 
            if not urls.match(e):
 
                links.append('<a class="message-link" href="%s">%s</a>' % (l, e))
 
            else:
 
                links.append(e)
 

	
 
        return ''.join(links)
 

	
 
    # urlify changesets - extrac revisions and make link out of them
 
    text_ = urlify_changesets(escaper(text_), repository)
 
    newtext = urlify_changesets(escaper(text_), repository)
 

	
 
    try:
 
        conf = config['app_conf']
 

	
 
        URL_PAT = re.compile(r'%s' % conf.get('issue_pat'))
 
        # allow multiple issue servers to be used
 
        valid_indices = [
 
            x.group(1) 
 
            for x in map(lambda x: re.match(r'issue_pat(.*)', x), conf.keys()) 
 
            if x and conf.has_key('issue_server_link'+x.group(1)) and conf.has_key('issue_prefix'+x.group(1))
 
            ]
 

	
 
        #log.debug('found issue server suffixes ' + ','.join(valid_indices) + ' during valuation of: \n' + newtext)
 

	
 
        if URL_PAT:
 
            ISSUE_SERVER_LNK = conf.get('issue_server_link')
 
            ISSUE_PREFIX = conf.get('issue_prefix')
 
        for pattern_index in valid_indices:
 
            ISSUE_PATTERN = conf.get('issue_pat'+pattern_index)
 
            ISSUE_SERVER_LNK = conf.get('issue_server_link'+pattern_index)
 
            ISSUE_PREFIX = conf.get('issue_prefix'+pattern_index)
 

	
 
            #log.debug(ISSUE_PATTERN + ' ' + ISSUE_SERVER_LNK + ' ' + ISSUE_PREFIX)
 

	
 
            URL_PAT = re.compile(r'%s' % ISSUE_PATTERN)
 

	
 
            def url_func(match_obj):
 
                pref = ''
 
                if match_obj.group().startswith(' '):
 
                    pref = ' '
 

	
 
                issue_id = ''.join(match_obj.groups())
 
                tmpl = (
 
                '%(pref)s<a class="%(cls)s" href="%(url)s">'
 
                '%(issue-prefix)s%(id-repr)s'
 
                '</a>'
 
                )
 
                url = ISSUE_SERVER_LNK.replace('{id}', issue_id)
 
                if repository:
 
                    url = url.replace('{repo}', repository)
 
                    repo_name = repository.split(URL_SEP)[-1]
 
                    url = url.replace('{repo_name}', repo_name)
 

	
 
                return tmpl % {
 
                     'pref': pref,
 
                     'cls': 'issue-tracker-link',
 
                     'url': url,
 
                     'id-repr': issue_id,
 
                     'issue-prefix': ISSUE_PREFIX,
 
                     'serv': ISSUE_SERVER_LNK,
 
                }
 

	
 
            newtext = URL_PAT.sub(url_func, text_)
 
            newtext = URL_PAT.sub(url_func, newtext)
 
            #log.debug('after '+pattern_index+':\n'+newtext)
 

	
 
        # if we actually did something above
 
        if valid_indices:
 
            if link_:
 
                # wrap not links into final link => link_
 
                newtext = linkify_others(newtext, link_)
 

	
 
            return literal(newtext)
 
    except:
 
        log.error(traceback.format_exc())
 
        pass
 

	
 
    return text_
 
    return newtext
 

	
 

	
 
def rst(source):
 
    return literal('<div class="rst-block">%s</div>' %
 
                   MarkupRenderer.rst(source))
 

	
 

	
 
def rst_w_mentions(source):
 
    """
 
    Wrapped rst renderer with @mention highlighting
 

	
 
    :param source:
0 comments (0 inline, 0 general)