sapling/hgext3rd/phabdiff.py
Wez Furlong 934dfaf08b templater: fixup for templater changes upstream
Summary:
The function signature for a number of functions relating to templating changed.

In addition, the templater layer now requires that template functions have been
registered via the decorator, otherwise a require attribute is missing and
things blow up.

Test Plan: arc unit.  rt.

Reviewers: #mercurial, quark

Reviewed By: quark

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4908220

Signature: t1:4908220:1492545033:66f089e03a6064ae96ca36f3abf99ecb6d48d422
2017-04-18 13:04:11 -07:00

30 lines
932 B
Python

# phabdiff.py
#
# Copyright 2013 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from mercurial import registrar, templatekw
from phabricator import diffprops
import re
templatekeyword = registrar.templatekeyword()
@templatekeyword('phabdiff')
def showphabdiff(repo, ctx, templ, **args):
"""String. Return the phabricator diff id for a given hg rev."""
descr = ctx.description()
revision = diffprops.parserevfromcommitmsg(descr)
return 'D' + revision if revision else ''
@templatekeyword('tasks')
def showtasks(**args):
"""String. Return the tasks associated with given hg rev."""
tasks = []
descr = args['ctx'].description()
match = re.search('(Tasks?|Task ID):(.*)', descr)
if match:
tasks = re.findall('\d+', match.group(0))
return templatekw.showlist('task', tasks, args)