]>
Commit | Line | Data |
---|---|---|
76e24b1f EB |
1 | from trac.core import * |
2 | from trac.ticket import ITicketChangeListener | |
6ae9f02e | 3 | import subprocess |
76e24b1f | 4 | import textwrap |
1246b147 | 5 | import shlex |
76e24b1f EB |
6 | |
7 | class ZephyrPlugin(Component): | |
cace67b2 EB |
8 | implements(ITicketChangeListener) |
9 | ||
10 | def zwrite(self, id, message): | |
11 | zclass = self.config.get('ZephyrPlugin', 'class') | |
12 | if zclass == '': | |
13 | return | |
1246b147 | 14 | command = shlex.split(self.config.get('ZephyrPlugin', 'command')) |
da9785cf | 15 | if not command: |
d23d10ba GT |
16 | command = ['zwrite', '-q', '-l', '-d'] |
17 | p = subprocess.Popen(command + | |
18 | ['-c', zclass, | |
cace67b2 EB |
19 | '-i', 'trac-#%s' % id], |
20 | stdin=subprocess.PIPE) | |
0e5f06a1 | 21 | p.stdin.write(message.replace('@', '@@').encode('utf-8', 'replace')) |
cace67b2 EB |
22 | p.stdin.close() |
23 | p.wait() | |
24 | ||
25 | def ticket_created(self, ticket): | |
606dbf12 EB |
26 | message = "%s filed a new ticket:\n%s\n\n%s" % (ticket['reporter'], |
27 | ticket['summary'], | |
28 | textwrap.fill(ticket['description'][:255])) | |
cace67b2 EB |
29 | self.zwrite(ticket.id, message) |
30 | ||
31 | def ticket_changed(self, ticket, comment, author, old_values): | |
32 | if old_values.has_key('status'): | |
33 | if ticket['status'] == 'closed': | |
34 | message = "%s closed ticket as %s\n(%s)" % (author, ticket['resolution'], ticket['summary']) | |
35 | else: | |
36 | message = "%s set status to %s\n(%s)" % (author, ticket['status'], ticket['summary']) | |
37 | else: | |
38 | message = "%s updated this ticket\n(%s)" % (author, ticket['summary']) | |
39 | self.zwrite(ticket.id, message) | |
40 | ||
41 | def ticket_deleted(self, ticket): | |
42 | pass |