]> sipb.mit.edu Git - snippets/.git/blobdiff - TracZephyrPlugin/ZephyrPlugin.py
TracZephyrPlugin: Bump version number.
[snippets/.git] / TracZephyrPlugin / ZephyrPlugin.py
index fe46914b486df5c0421e11671329332672f55ddf..aeaec986f583dc3c9347892a966b34e33f4c4d0b 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,9 +16,12 @@ 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']
+        opcode = self.config.get('ZephyrPlugin', 'opcode')
+        if opcode:
+            command += ['-O', opcode]
         p = subprocess.Popen(command +
                              ['-c', zclass,
                               '-i', 'trac-#%s' % id],
@@ -23,19 +31,21 @@ 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'[…]']
         return '\n'.join(lines)
     
     def ticket_created(self, ticket):
-        message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'],
-                                                        ticket['summary'],
-                                                        self.format_text(ticket['description']))
+        message = "%s filed a new %s ticket:\n%s\n\n%s" % (ticket['reporter'],
+                                                           ticket['priority'],
+                                                           ticket['summary'],
+                                                           self.format_text(ticket['description']))
         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: