Download:
child 5:0b8327ad3140
parent 3:096e1a63071c
4:cf0cac509fcf
Brendan Cully <brendan@cs.ubc.ca>, Thu, 25 Jun 2009 09:04:30 -0700
Allow multiple repositories

1 файлов изменено, 93 вставок(+), 12 удалений(-) [+]
plugin.py file | annotate | diff | comparison | revisions
--- a/plugin.py Sat May 30 21:32:17 2009 -0700
+++ b/plugin.py Thu Jun 25 09:04:30 2009 -0700
@@ -36,6 +36,70 @@
import os
+import urllib
+import logging
+
+fields = {'issue':'title',
+ 'msg':'content',
+ 'file':'description',
+ }
+
+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')
+ "Incorporated as:
+ 2.7: r69419
+ 3.1: r69421"
+
+ 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')
+ 'None'
+ """
+
+ # This should be the smallest query able to fetch what we need
+ query_tpl = [('@action', 'export_csv'), ('@filter', 'id'),
+ ('id', nodeid), ('@columns', fields[kind])]
+ # Request path + query
+ 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 '''
+
+ kind = 'issue'
+ if nodeid.startswith('msg'):
+ kind = 'msg'
+ elif nodeid.startswith('file'):
+ kind = 'file'
+ nodeid = nodeid.replace(kind, '')
+ result = fetch_item(int(nodeid), kind)
+ if not result:
+ result = 'No item found for %s%s' % (kind, nodeid)
+ if debug:
+ logging.info('Fetched "%s: %s"' % (kind, result))
+ return result
+
def revparse(irc, msg, args, state):
if ':' in args[0]:
state.errorInvalid('revision', args[0],
@@ -81,12 +145,8 @@
hghelp = wrap(hghelp, ['text'])
- def crew(self, irc, msg, args, rev):
- "gets the changelog message for the given revision"
-
- # make configurable
- 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)
fd = os.popen(cmd)
@@ -94,20 +154,41 @@
fd.close()
if not out:
- irc.reply('No result found.')
- return
+ return ['No result found.']
lines = [x for x in out.strip().splitlines() if x]
rev, date, user, files = lines[:4]
lines = lines[4:]
rev = ircutils.bold(rev)
user = ircutils.mircColor(user, fg='green')
- date = ircutils.mircColor(date, fg='black')
+
+ lines = ['%s %s %s' % (rev, user, date)] + lines
+ return lines[:2]
+
+ 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)
+ irc.replies(cl)
+ crew = wrap(crew, ['revision'])
- lines = ['%s %s %s: %s' % (rev, user, date, files)] + lines
- irc.replies(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)
+ irc.replies(cl)
+ main = wrap(main, ['revision'])
- crew = wrap(crew, ['revision'])
+ def bts(self, irc, msg, args, issue):
+ if issue == 'url':
+ irc.reply('http://mercurial.selenic.com/bts')
+ return None
+
+ title = fetch(issue)
+ if title.startswith('[issue'):
+ end = title.find(']') + 1
+ title = ircutils.bold(title[:end]) + title[end:]
+ title = title.replace('\n', ' ')
+ irc.reply(title)
+ bts = wrap(bts, ['text'])
Class = Mercurial