diff rhodecode/lib/helpers.py @ 1837:a6a30c919513 beta

#73 mapping of commited issues from commit message into issue tracker url.
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 06 Jan 2012 19:27:32 +0200
parents b9708d66277c
children 87920d4f58c5
line wrap: on
line diff
--- a/rhodecode/lib/helpers.py	Fri Jan 06 06:39:54 2012 +0200
+++ b/rhodecode/lib/helpers.py	Fri Jan 06 19:27:32 2012 +0200
@@ -8,6 +8,7 @@
 import StringIO
 import urllib
 import math
+import logging
 
 from datetime import datetime
 from pygments.formatters.html import HtmlFormatter
@@ -41,6 +42,8 @@
 from rhodecode.lib import str2bool, safe_unicode, safe_str, get_changeset_safe
 from rhodecode.lib.markup_renderer import MarkupRenderer
 
+log = logging.getLogger(__name__)
+
 
 def _reset(name, value=None, id=NotGiven, type="reset", **attrs):
     """
@@ -740,6 +743,33 @@
 
     return literal(url_pat.sub(url_func, text))
 
+def urlify_commit(text):
+    import re
+    import traceback
+    
+    try:
+        conf = config['app_conf']
+        
+        URL_PAT = re.compile(r'%s' % conf.get('url_pat'))
+        
+        if URL_PAT:
+            ISSUE_SERVER = conf.get('issue_server')
+            ISSUE_PREFIX = conf.get('issue_prefix')
+            def url_func(match_obj):
+                issue_id = match_obj.groups()[0]
+                return ' <a href="%(url)s">%(issue-prefix)s%(id-repr)s</a>' % (
+                    {'url':ISSUE_SERVER.replace('{id}',issue_id),
+                     'id-repr':issue_id,
+                     'issue-prefix':ISSUE_PREFIX,
+                     'serv':ISSUE_SERVER,
+                    }
+                )
+            return literal(URL_PAT.sub(url_func, text))
+    except:
+        log.error(traceback.format_exc())
+        pass
+
+    return text
 
 def rst(source):
     return literal('<div class="rst-block">%s</div>' %