]> snippets.scripts.mit.edu Git - Scripts/git/.git/blobdiff - TracZephyrPlugin/ZephyrPlugin.py
TracZephyrPlugin: Smarter quoted text regex.
[Scripts/git/.git] / TracZephyrPlugin / ZephyrPlugin.py
index fe46914b486df5c0421e11671329332672f55ddf..679d019f962274877cc4bfb63e32cd3a905b6be8 100644 (file)
@@ -1,9 +1,14 @@
+# -*- coding: utf-8 -*-
+
 from trac.core import *
 from trac.ticket import ITicketChangeListener
 import subprocess
+import re
 import textwrap
 import shlex
 
+quoted_re = re.compile('^(?:> ?\n)*> .+\n(?:>(?: .*)?\n)*', re.MULTILINE)
+
 class ZephyrPlugin(Component):
     implements(ITicketChangeListener)
     
@@ -11,7 +16,7 @@ class ZephyrPlugin(Component):
         zclass = self.config.get('ZephyrPlugin', 'class')
         if zclass == '':
             return
-        command = shlex.split(self.config.get('ZephyrPlugin', 'command'))
+        command = shlex.split(self.config.get('ZephyrPlugin', 'command').encode('utf-8'))
         if not command:
             command = ['zwrite', '-q', '-l', '-d']
         p = subprocess.Popen(command +
@@ -23,6 +28,7 @@ class ZephyrPlugin(Component):
         p.wait()
 
     def format_text(self, text):
+        text = re.sub(quoted_re, u'> […]\n', text)
         lines = textwrap.fill(text).split('\n')
         if len(lines) > 5:
             lines = lines[:5] + [u'[…]']
@@ -35,7 +41,7 @@ class ZephyrPlugin(Component):
         self.zwrite(ticket.id, message)
     
     def ticket_changed(self, ticket, comment, author, old_values):
-        message = ''
+        message = "(%s)\n" % ticket['summary']
         for field in ticket.fields:
             name = field['name']
             if name not in old_values: