--- a/plugin.py Sat May 30 21:32:17 2009 -0700
+++ b/plugin.py Thu Jun 25 09:04:30 2009 -0700
+fields = {'issue':'title',
+def fetch_item(nodeid, kind='issue', tracker='http://mercurial.selenic.com/bts'):
+ """Use Roundup's CSV exports to fetch arbitrary item descriptions
+ Default behavior is to return subject for a new issue:
+ >>> fetch_item(1201569)
+ '[issue1201569] allow running multiple instances of IDLE'
+ Can also fetch message contents:
+ >>> fetch_item(108, 'msg')
+ 'Assigned to Guido for obvious reasons.'
+ Multiline messages have spurious quotes, thanks to CSV format:
+ >>> print fetch_item(81362, 'msg')
+ File descriptions work too:
+ >>> fetch_item(102, 'file')
+ 'Example of message from frustrated user on c.l.py'
+ Missing descriptions show as 'None':
+ >>> fetch_item(12227, 'file')
+ # This should be the smallest query able to fetch what we need
+ query_tpl = [('@action', 'export_csv'), ('@filter', 'id'),
+ ('id', nodeid), ('@columns', fields[kind])]
+ item_url = '/%s?%s' % (kind, urllib.urlencode(query_tpl))
+ content = urllib.urlopen(tracker + item_url).read().split('\r\n')
+ if content[0] == 'title':
+ # Got a single data row CSV, format and return it
+ return '[issue%s] %s' % (nodeid, content[1].strip())
+ elif content[0] == 'content':
+ return content[1].strip()
+ elif content[0] == 'description':
+ return content[1].strip()
+def fetch(nodeid, debug=True):
+ ''' Format input for fetch_item, add debug messages '''
+ if nodeid.startswith('msg'):
+ elif nodeid.startswith('file'):
+ nodeid = nodeid.replace(kind, '')
+ result = fetch_item(int(nodeid), kind)
+ result = 'No item found for %s%s' % (kind, nodeid)
+ logging.info('Fetched "%s: %s"' % (kind, result))
def revparse(irc, msg, args, state):
state.errorInvalid('revision', args[0],
hghelp = wrap(hghelp, ['text'])
- def crew(self, irc, msg, args, rev):
- "gets the changelog message for the given revision"
- repo = '/home/brendan/hg/mercurial/crew'
- tmpl = '{rev}:{node|short}\n{date|age} ago\n{author}\n{files}\n{desc}'
+ def changeLog(self, repo, rev):
+ tmpl = '{rev}:{node|short}\n{date|age} ago\n{author|person}\n{files}\n{desc}'
cmd = "%s -R %s log -v --limit 1 --template '%s' -r %s" \
% (self.path, repo, tmpl, rev)
- irc.reply('No result found.')
+ return ['No result found.']
lines = [x for x in out.strip().splitlines() if x]
rev, date, user, files = lines[:4]
user = ircutils.mircColor(user, fg='green')
- date = ircutils.mircColor(date, fg='black')
+ lines = ['%s %s %s' % (rev, user, date)] + lines
+ def crew(self, irc, msg, args, rev):
+ "gets the changelog message for the given revision of the crew repository"
+ cl = self.changeLog('/home/brendan/hg/mercurial/crew', rev)
+ crew = wrap(crew, ['revision'])
- lines = ['%s %s %s: %s' % (rev, user, date, files)] + lines
+ def main(self, irc, msg, args, rev):
+ "gets the changelog message for the given revision of the crew repository"
+ cl = self.changeLog('/home/brendan/hg/mercurial/main', rev)
+ main = wrap(main, ['revision'])
- crew = wrap(crew, ['revision'])
+ def bts(self, irc, msg, args, issue):
+ irc.reply('http://mercurial.selenic.com/bts')
+ if title.startswith('[issue'):
+ end = title.find(']') + 1
+ title = ircutils.bold(title[:end]) + title[end:]
+ title = title.replace('\n', ' ')
+ bts = wrap(bts, ['text'])