changeset 14314:c322890b03e6

hgcia: Handle URL like in notify (issue2406) The URL must be composed with baseurl and webroot like in notify
author Cédric Krier <ced@b2ck.com>
date Wed, 11 May 2011 18:18:50 +0200
parents a389dd285282
children f6b3b346d80c
files hgext/hgcia.py tests/test-hgcia.t
diffstat 2 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/hgcia.py	Thu May 12 16:41:56 2011 +0200
+++ b/hgext/hgcia.py	Wed May 11 18:18:50 2011 +0200
@@ -18,7 +18,7 @@
   # Append a diffstat to the log message (optional)
   #diffstat = False
   # Template to use for log messages (optional)
-  #template = {desc}\\n{baseurl}/rev/{node}-- {diffstat}
+  #template = {desc}\\n{baseurl}{webroot}/rev/{node}-- {diffstat}
   # Style to use (optional)
   #style = foo
   # The URL of the CIA notification service (optional)
@@ -28,6 +28,8 @@
   #url = http://cia.vc/
   # print message instead of sending it (optional)
   #test = False
+  # number of slashes to strip for url paths
+  #strip = 0
 
   [hooks]
   # one of these:
@@ -66,6 +68,8 @@
         self.cia = cia
         self.ctx = ctx
         self.url = self.cia.url
+        if self.url:
+            self.url += self.cia.root
 
     def fileelem(self, path, uri, action):
         if uri:
@@ -120,7 +124,9 @@
         diffstat = self.cia.diffstat and self.diffstat() or ''
         self.cia.ui.pushbuffer()
         self.cia.templater.show(self.ctx, changes=self.ctx.changeset(),
-                                url=self.cia.url, diffstat=diffstat)
+                                baseurl=self.cia.ui.config('web', 'baseurl'),
+                                url=self.url, diffstat=diffstat,
+                                webroot=self.cia.root)
         return self.cia.ui.popbuffer()
 
     def xml(self):
@@ -184,6 +190,8 @@
         self.emailfrom = self.ui.config('email', 'from')
         self.dryrun = self.ui.configbool('cia', 'test')
         self.url = self.ui.config('web', 'baseurl')
+        self.stripcount = int(self.ui.config('cia', 'strip', 0))
+        self.root = self.strip(self.repo.root)
 
         style = self.ui.config('cia', 'style')
         template = self.ui.config('cia', 'template')
@@ -195,6 +203,19 @@
         t.use_template(template)
         self.templater = t
 
+    def strip(self, path):
+        '''strip leading slashes from local path, turn into web-safe path.'''
+
+        path = util.pconvert(path)
+        count = self.stripcount
+        while count > 0:
+            c = path.find('/')
+            if c == -1:
+                break
+            path = path[c + 1:]
+            count -= 1
+        return path
+
     def sendrpc(self, msg):
         srv = xmlrpclib.Server(self.ciaurl)
         res = srv.hub.deliver(msg)
--- a/tests/test-hgcia.t	Thu May 12 16:41:56 2011 +0200
+++ b/tests/test-hgcia.t	Wed May 11 18:18:50 2011 +0200
@@ -7,6 +7,9 @@
   > [hooks]
   > changegroup.cia = python:hgext.hgcia.hook
   > 
+  > [web]
+  > baseurl = http://hgserver/
+  > 
   > [cia]
   > user = testuser
   > project = testproject
@@ -43,8 +46,8 @@
         <author>test</author>
         <version>0:e63c23eaa88a</version>
         <log>foo</log>
-        
-        <files><file action="add">foo</file></files>
+        <url>http://hgserver/$TESTTMP/cia/rev/e63c23eaa88a</url>
+        <files><file uri="http://hgserver/$TESTTMP/cia/file/e63c23eaa88a/foo" action="add">foo</file></files>
       </commit>
     </body>
     <timestamp>0</timestamp>