--- a/config.py Thu Nov 22 14:40:59 2018 +0800
+++ b/config.py Thu Nov 22 15:27:58 2018 +0800
conf.registerGlobalValue(Mercurial.repos, 'hg-all',
registry.String('/home/hg/repos/hg-all',
"""Path to the hg-all repo."""))
+conf.registerGlobalValue(Mercurial, 'phaburl',
+ registry.String('https://phab.mercurial-scm.org',
+ """URL of the phabricator instance."""))
--- a/plugin.py Thu Nov 22 14:40:59 2018 +0800
+++ b/plugin.py Thu Nov 22 15:27:58 2018 +0800
from supybot.commands import *
def revparse(irc, msg, args, state):
- state.errorInvalid('revision', args[0],
+ state.errorInvalid('revision', args[0], 'Contains ":".')
state.args.append(args.pop(0))
addConverter('revision', revparse)
+def phabrevparse(irc, msg, args, state):
+ if args[0].startswith('D'):
+ callConverter('positiveInt', irc, msg, args, state)
+addConverter('phabrev', phabrevparse)
def __init__(self, path):
irc.reply('no match found')
glossary = wrap(glossary, ['text'])
+ def differential(self, irc, msg, args, phabrev, gotURL=False):
+ Returns URL, description and status of revisions on differential."""
+ baseurl = self.registryValue('phaburl')
+ url = '{}/D{}'.format(baseurl.rstrip('/'), phabrev)
+ page = utils.web.getUrl(url).decode('utf-8')
+ desc = 'Description N/A'
+ match = re.search(r'<div class="phui-header-subheader">.*?</span>(?P<status>[^<]+?)</span>', page)
+ status = utils.web.htmlToText(match.group('status'))
+ match = re.search(r'<span class="phui-header-header">.*?</span>(?P<desc>[^<]+?)</span>', page)
+ desc = utils.web.htmlToText(match.group('desc'))
+ url = 'D{}'.format(phabrev)
+ item = 'Revision {} {}, {}'.format(url, status, desc)
+ differential = wrap(differential, ['phabrev'])
--- a/test.py Thu Nov 22 14:40:59 2018 +0800
+++ b/test.py Thu Nov 22 15:27:58 2018 +0800
self.assertNotError('main null')
+ def testDifferential(self):
+ self.assertResponse('differential 3850',
+ 'Revision https://phab.mercurial-scm.org/D3850'
+ ' Closed, stringutil: update list of re-special characters to include &~')
+ self.assertResponse('differential D5194',
+ 'Revision https://phab.mercurial-scm.org/D5194'
+ ' Abandoned, wireprotov2: add an extension to cache wireproto v2 responses in S3')
+ self.assertHelp('differential')
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: