X-Git-Url: https://snippets.scripts.mit.edu/gitweb.cgi/Scripts/git/.git/blobdiff_plain/8293875f77dc4d04b04f3a76019f4daeabcc0fc3..a7c202e35cf46295abd47908631b8e3669a096e2:/TracZephyrPlugin/ZephyrPlugin.py diff --git a/TracZephyrPlugin/ZephyrPlugin.py b/TracZephyrPlugin/ZephyrPlugin.py index 9792da4..673c339 100644 --- a/TracZephyrPlugin/ZephyrPlugin.py +++ b/TracZephyrPlugin/ZephyrPlugin.py @@ -3,9 +3,12 @@ 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) @@ -16,6 +19,12 @@ class ZephyrPlugin(Component): 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] + signature = self.config.get('ZephyrPlugin', 'signature') + if signature: + command += ['-s', signature] p = subprocess.Popen(command + ['-c', zclass, '-i', 'trac-#%s' % id], @@ -25,15 +34,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'])) + ttype='ticket' + if ticket['type'] != 'defect': + ttype=ticket['type'] + message = "%s filed a new %s %s:\n%s\n\n%s" % (ticket['reporter'], + ticket['priority'], + ttype, + ticket['summary'], + self.format_text(ticket['description'])) self.zwrite(ticket.id, message) def ticket_changed(self, ticket, comment, author, old_values):