Download:
child 31:c3c5a64068a5
parent 29:8f03cd5eaace
30:8db5c52046c7 draft
Anton Shestakov <av6@dwimlabs.net>, Thu, 22 Nov 2018 15:27:58 +0800
plugin: add a basic differential parser

3 файлов изменено, 45 вставок(+), 2 удалений(-) [+]
config.py file | annotate | diff | comparison | revisions
plugin.py file | annotate | diff | comparison | revisions
test.py file | annotate | diff | comparison | revisions
--- a/config.py Thu Nov 22 14:40:59 2018 +0800
+++ b/config.py Thu Nov 22 15:27:58 2018 +0800
@@ -57,3 +57,7 @@
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
@@ -32,15 +32,21 @@
from supybot.commands import *
import os
+import re
import subprocess
def revparse(irc, msg, args, state):
if ':' in args[0]:
- state.errorInvalid('revision', args[0],
- 'Contains ":".')
+ 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'):
+ args[0] = args[0][1:]
+ callConverter('positiveInt', irc, msg, args, state)
+addConverter('phabrev', phabrevparse)
+
class Hg(object):
def __init__(self, path):
self.path = path
@@ -150,4 +156,28 @@
irc.reply('no match found')
glossary = wrap(glossary, ['text'])
+ def differential(self, irc, msg, args, phabrev, gotURL=False):
+ """<revision id>
+
+ 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')
+
+ status = 'Status N/A'
+ desc = 'Description N/A'
+ match = re.search(r'<div class="phui-header-subheader">.*?</span>(?P<status>[^<]+?)</span>', page)
+ if match:
+ status = utils.web.htmlToText(match.group('status'))
+ match = re.search(r'<span class="phui-header-header">.*?</span>(?P<desc>[^<]+?)</span>', page)
+ if match:
+ desc = utils.web.htmlToText(match.group('desc'))
+
+ if gotURL:
+ url = 'D{}'.format(phabrev)
+
+ item = 'Revision {} {}, {}'.format(url, status, desc)
+ irc.reply(item)
+ differential = wrap(differential, ['phabrev'])
+
Class = Mercurial
--- a/test.py Thu Nov 22 14:40:59 2018 +0800
+++ b/test.py Thu Nov 22 15:27:58 2018 +0800
@@ -50,4 +50,13 @@
self.assertNotError('main null')
self.assertHelp('main')
+ 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: