sapling/hgext/phabdiff.py
Xiaolong Wang 69161e4c0d add template for fetching reviewers
Summary: as titled, so that we can `hg log -T {reviewers} --rev .`

Reviewed By: quark-zju

Differential Revision: D8389944

fbshipit-source-id: b3b194b7027bc831d5eca42dfcb4300745d6eb12
2018-06-12 20:48:50 -07:00

56 lines
1.6 KiB
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.
import re
from mercurial import registrar, templatekw
from mercurial.node import hex
from .extlib.phabricator import diffprops
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)
@templatekeyword("singlepublicbase")
def singlepublicbase(repo, ctx, templ, **args):
"""String. Return the public base commit hash."""
base = repo.revs("last(::%d - not public())", ctx.rev())
if len(base):
return hex(repo[base.first()].node())
return ""
@templatekeyword("reviewers")
def showreviewers(repo, **args):
"""String. Return the phabricator diff id for a given hg rev."""
reviewers = []
descr = args["ctx"].description()
match = re.search("Reviewers:(.*)", descr)
if match:
reviewers = filter(None, re.split("[\s,]", match.group(1)))
return templatekw.showlist("reviewer", reviewers, args)