changeset f7ccd068dd3c in trypod:default
details: https://hg.tryton.org/trypod?cmd=changeset;node=f7ccd068dd3c
description:
Add support for Python3 for mercurial hook
diffstat:
hook.py | 39 ++++++++++++++++++++-------------------
1 files changed, 20 insertions(+), 19 deletions(-)
diffs (86 lines):
diff -r ae5c8462f882 -r f7ccd068dd3c hook.py
--- a/hook.py Tue Jul 14 09:26:52 2020 +0200
+++ b/hook.py Sun Sep 27 17:07:30 2020 +0200
@@ -6,6 +6,7 @@
from mercurial import util
from mercurial.utils import stringutil
from mercurial.templatefilters import firstline
+from mercurial.encoding import unifromlocal
# demandimport breaks requests
try:
from mercurial import demandimport
@@ -16,41 +17,41 @@
def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
- if hooktype not in ['commit', 'incoming']:
- ui.debug('trypod: wrong hook type %s\n' % hooktype)
+ if hooktype not in [b'commit', b'incoming']:
+ ui.debug(b'trypod: wrong hook type %s\n' % hooktype)
return
ctx = repo[node]
- root = strip(repo.root, int(ui.config('trypod', 'strip', -1)))
- repourl = ui.config('web', 'baseurl')
+ root = strip(repo.root, int(ui.config(b'trypod', b'strip', -1)))
+ repourl = ui.config(b'web', b'baseurl')
if repourl:
repourl += root
branch = ctx.branch()
- email = stringutil.email(ctx.user())
+ email = unifromlocal(stringutil.email(ctx.user()))
payload = {
'author': email,
'avatar': avatar(email),
- 'repository': repourl,
- 'owner': ui.config('trypod', 'owner'),
- 'name': root.replace('/', '.'),
- 'rev': ctx.hex(),
- 'branch': branch,
- 'description': firstline(ctx.description().strip()),
+ 'repository': unifromlocal(repourl),
+ 'owner': unifromlocal(ui.config(b'trypod', b'owner')),
+ 'name': unifromlocal(root.replace(b'/', b'.')),
+ 'rev': unifromlocal(ctx.hex()),
+ 'branch': unifromlocal(branch),
+ 'description': unifromlocal(firstline(ctx.description().strip())),
}
- url = ui.config('trypod', 'url_%s' % branch)
+ url = ui.config(b'trypod', b'url_%s' % branch)
if url is None:
- url = ui.config('trypod', 'url')
- token = ui.config('trypod', 'token_%s' % branch)
+ url = ui.config(b'trypod', b'url')
+ token = ui.config(b'trypod', b'token_%s' % branch)
if token is None:
- token = ui.config('trypod', 'token')
+ token = ui.config(b'trypod', b'token')
if token:
url += '/' + token
- ui.status('trypod: trigger drone build\n')
+ ui.status(b'trypod: trigger drone build\n')
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url, data=json.dumps(payload), headers=headers)
if r.status_code != requests.codes.ok:
- ui.warn('trypod: post failed %s\n' % r.status_code)
+ ui.warn(b'trypod: post failed %s\n' % r.status_code)
def strip(path, count):
@@ -60,7 +61,7 @@
if count < 0:
return
while count > 0:
- c = path.find('/')
+ c = path.find(b'/')
if c == -1:
break
path = path[c + 1:]
@@ -69,5 +70,5 @@
def avatar(email):
- digest = hashlib.md5(email.strip()).hexdigest()
+ digest = hashlib.md5(email.strip().encode('utf-8')).hexdigest()
return 'https://www.gravatar.com/avatar/' + digest