Merge lp://staging/~mgorven/ibid/trac-338708 into lp://staging/~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Michael Gorven
Status: Merged
Approved by: Michael Gorven
Approved revision: 564
Merged at revision: 561
Proposed branch: lp://staging/~mgorven/ibid/trac-338708
Merge into: lp://staging/~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: None lines
To merge this branch: bzr merge lp://staging/~mgorven/ibid/trac-338708
Reviewer Review Type Date Requested Status
Stefano Rivera Approve
Review via email: mp+4231@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

Code looks good, although I can't test it as I don't have a trac lying around.

review: Approve
563. By Michael Gorven

Allow tickets to be listed by milestone.

Revision history for this message
Michael Gorven (mgorven) wrote :

Added listing tickets by milestone.

564. By Michael Gorven

Display owner when listing tickets.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/trac.py'
2--- ibid/plugins/trac.py 2009-03-01 23:01:30 +0000
3+++ ibid/plugins/trac.py 2009-03-06 11:58:09 +0000
4@@ -1,4 +1,6 @@
5 from datetime import datetime
6+from simplejson import loads
7+import logging
8
9 from sqlalchemy import Table, MetaData
10 from sqlalchemy.orm import mapper
11@@ -6,7 +8,7 @@
12
13 import ibid
14 from ibid.plugins import Processor, match, RPC
15-from ibid.config import Option
16+from ibid.config import Option, BoolOption
17 from ibid.utils import ago
18
19 help = {'trac': u'Retrieves tickets from a Trac database.'}
20@@ -19,7 +21,7 @@
21 ticket_table = Table('ticket', metadata, autoload=True)
22 mapper(Ticket, ticket_table)
23
24-class GetTicket(Processor, RPC):
25+class Tickets(Processor, RPC):
26 u"""ticket <number>
27 (open|my|<who>'s) tickets"""
28 feature = 'trac'
29@@ -27,23 +29,47 @@
30 url = Option('url', 'URL of Trac instance')
31 source = Option('source', 'Source to send commit notifications to')
32 channel = Option('channel', 'Channel to send commit notifications to')
33+ announce_changes = BoolOption('announce_changes', u'Announce changes to tickets', True)
34
35 def __init__(self, name):
36 Processor.__init__(self, name)
37 RPC.__init__(self)
38+ self.log = logging.getLogger('plugins.trac')
39
40 def get_ticket(self, id):
41 session = ibid.databases.trac()
42 ticket = session.query(Ticket).get(id)
43 session.close()
44- return ticket and u'Ticket %s (%s %s %s) reported by %s %s ago assigned to %s: "%s" %sticket/%s' % (ticket.id, ticket.status, ticket.priority, ticket.type, ticket.reporter, ago(datetime.now() - datetime.fromtimestamp(ticket.time), 2), ticket.owner, ticket.summary, self.url, ticket.id) or None
45+ return ticket
46
47- def remote_newticket(self, id):
48+ def remote_ticket_created(self, id):
49 ticket = self.get_ticket(id)
50 if not ticket:
51 raise Exception(u"No such ticket")
52
53- ibid.dispatcher.send({'reply': ticket, 'source': self.source, 'target': self.channel})
54+ message = u'New %s in %s reported by %s: "%s" %sticket/%s' % (ticket.type, ticket.component, ticket.reporter, ticket.summary, self.url, ticket.id)
55+ ibid.dispatcher.send({'reply': message, 'source': self.source, 'target': self.channel})
56+ self.log.info(u'Ticket %s created', id)
57+ return True
58+
59+ def remote_ticket_changed(self, id, comment, author, old_values):
60+ if not self.announce_changes:
61+ return False
62+
63+ ticket = self.get_ticket(id)
64+ if not ticket:
65+ raise Exception(u'No such ticket')
66+
67+ changes = []
68+ for field, old in old_values.items():
69+ if hasattr(ticket, field):
70+ changes.append(u'%s: %s' % (field, getattr(ticket, field)))
71+ if comment:
72+ changes.append(u'comment: "%s"' % comment)
73+
74+ message = u'Ticket %s (%s %s %s in %s for %s) modified by %s. %s' % (id, ticket.status, ticket.priority, ticket.type, ticket.component, ticket.milestone, author, u', '.join(changes))
75+ ibid.dispatcher.send({'reply': message, 'source': self.source, 'target': self.channel})
76+ self.log.info(u'Ticket %s modified', id)
77 return True
78
79 @match(r'^ticket\s+(\d+)$')
80@@ -51,7 +77,7 @@
81 ticket = self.get_ticket(int(number))
82
83 if ticket:
84- event.addresponse(ticket)
85+ event.addresponse(u'Ticket %s (%s %s %s in %s for %s) reported %s ago assigned to %s: "%s" %sticket/%s' % (ticket.id, ticket.status, ticket.priority, ticket.type, ticket.component, ticket.milestone, ago(datetime.now() - datetime.fromtimestamp(ticket.time), 2), ticket.owner, ticket.summary, self.url, ticket.id))
86 else:
87 event.addresponse(u"No such ticket")
88
89
90=== modified file 'tracibid/notifier.py'
91--- tracibid/notifier.py 2009-01-29 15:17:04 +0000
92+++ tracibid/notifier.py 2009-03-06 11:41:56 +0000
93@@ -1,12 +1,14 @@
94+from urllib import urlencode
95 from urllib2 import urlopen
96+from simplejson import dumps
97 from threading import Timer
98
99 from trac.core import *
100 from trac.ticket import ITicketChangeListener
101 from trac.config import Option
102
103-def notify(boturl, ticket_id):
104- urlopen('%s/trac/newticket/%s' % (boturl, ticket_id)).close()
105+def notify(url, data):
106+ urlopen(url, urlencode(data)).close()
107
108 class IbidNotifier(Component):
109 implements(ITicketChangeListener)
110@@ -14,10 +16,10 @@
111 boturl = Option('tracibid', 'boturl', 'http://localhost:8080', 'URL of Ibid instance')
112
113 def ticket_created(self, ticket):
114- Timer(5, notify, [self.boturl, ticket.id]).start()
115+ Timer(2, notify, [self.boturl+'/trac/ticket_created', {'id': ticket.id}]).start()
116
117 def ticket_changed(self, ticket, comment, author, old_values):
118- pass
119+ Timer(2, notify, [self.boturl+'/trac/ticket_changed', {'id': ticket.id, 'comment': comment, 'author': author, 'old_values': dumps(old_values)}]).start()
120
121 def ticket_deleted(self, ticket):
122 pass

Subscribers

People subscribed via source and target branches