Thursday, May 10, 2007

Add Mantis links to ViewVC (ViewCVS)

A small modification to ViewVC adding links to our mantis system:

--- lib/viewvc.py.orig  2007-05-10 10:39:10.000000000 +0800
+++ lib/viewvc.py       2007-05-10 11:17:00.000000000 +0800
@@ -973,10 +973,12 @@
 # addresses.  Note that the regexps assume the text is already HTML-encoded.
 _re_rewrite_url = re.compile('((http|https|ftp|file|svn|svn\+ssh)(://[-a-zA-Z0-9%.~:_/]+)((\?|\&)([-a-zA-Z0-9%.~:_]+)=([-a-zA-Z0-9%.~:_])+)*(#([-a-zA-Z0-9%.~:_]+)?)?)')
 _re_rewrite_email = re.compile('([-a-zA-Z0-9_.\+]+)@(([-a-zA-Z0-9]+\.)+[A-Za-z]{2,4})')
+_re_rewrite_mantis = re.compile('(issue)([\ \#]+)(\d{1,7})')
 def htmlify(html):
   html = cgi.escape(html)
   html = re.sub(_re_rewrite_url, r'<a href="\1">\1</a>', html)
   html = re.sub(_re_rewrite_email, r'<a href="mailto:\1&#64;\2">\1&#64;\2</a>', html)
+  html = re.sub(_re_rewrite_mantis, r'<a href="/mantis/view.php?id=\3">\1\2\3</a>', html)
   return html

 def format_log(log, cfg):
@@ -1310,6 +1312,7 @@
   html = pp.fontify(html)
   html = re.sub(_re_rewrite_url, r'<a href="\1">\1</a>', html)
   html = re.sub(_re_rewrite_email, r'<a href="mailto:\1">\1</a>', html)
+  html = re.sub(_re_rewrite_mantis, r'<a href="/mantis/view.php?id=\3">\1\2\3</a>', html)
   return html

 def markup_stream_php(fp, cfg):

I believe it would be quite easy to understand the modification, which substitutes 'issue #id' to an URL link to mantis system.

For automatically adding a note to mantis when commit to CVS, please reference CVS Integration in Mantis manual.

5 comments:

玉麒麟 said...

Why I fail to add mantis links to viewvc?

I use "issue id", e.g. "issue 1" not "issue #1" in subversion, then how should I rewrite the viewvc.py? wengyq@gmail.com

Winfred said...

All you have to do is to modify regular expression syntax.
Try using the followed codes instead.

line 976:
_re_rewrite_mantis = re.compile('(issue\ )(\d{1,7})')

line 981:
html = re.sub(_re_rewrite_mantis, r'<a href="/mantis/view.php?id=\2">\1\2</a>', html)

line 1315:
html = re.sub(_re_rewrite_mantis, r'<a href="/mantis/view.php?id=">\1\2</a>', html)

John Pye said...

The patch file is wrong. It looks as though the backslashes have been vanished by your blog software.

John Pye said...

I've written a vice-versa thing that links from Mantis to ViewVC. See this page on the ASCEND wiki.

Winfred said...

Thanks a lot, John Pye. The previous patch file was displayed incorrectly. I have already fixed it.