Patchwork D7507: phabricator: add a "phabstatus" template keyword

login
register
mail settings
Submitter phabricator
Date Nov. 22, 2019, 4 p.m.
Message ID <differential-rev-PHID-DREV-ufixx5mxw6i46kdhakhf-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43442/
State Superseded
Headers show

Comments

phabricator - Nov. 22, 2019, 4 p.m.
dlax created this revision.
Herald added subscribers: mercurial-devel, Kwan.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We add a "phabstatus" template keyword, returning an object with "url"
  and "status" keys. This is quite similar to "phabreview" template
  keyword, but it queries phabricator for each specified revision so it's
  going to be slow (as compared to the "phabstatus" show view from
  previous changeset).

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7507

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS




To: dlax, #hg-reviewers
Cc: Kwan, mercurial-devel
phabricator - Nov. 23, 2019, 4:23 p.m.
mharbison72 added a comment.


  I only have a superficial understanding about how templates work, but I assume that there's no global pre-resolution step where a single query could be done and the results stuffed into the context or something, is there?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7507/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7507

To: dlax, #hg-reviewers
Cc: mharbison72, Kwan, mercurial-devel
phabricator - Nov. 23, 2019, 4:45 p.m.
dlax added a comment.


  >   I only have a superficial understanding about how templates work, but I assume that there's no global pre-resolution step where a single query could be done and the results stuffed into the context or something, is there?
  
  Not that I am aware. Using this keyword on large revsets is indeed slow.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7507/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7507

To: dlax, #hg-reviewers
Cc: mharbison72, Kwan, mercurial-devel

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -1682,6 +1682,28 @@ 
     return None
 
 
+@eh.templatekeyword(b'phabstatus', requires={b'ctx', b'repo', b'ui'})
+def template_status(context, mapping):
+    """:phabstatus: String. Status of Phabricator differential.
+    """
+    ctx = context.resource(mapping, b'ctx')
+    repo = context.resource(mapping, b'repo')
+    ui = context.resource(mapping, b'ui')
+
+    rev = ctx.rev()
+    try:
+        drevid = getdrevmap(repo, [rev])[rev]
+    except KeyError:
+        return None
+    drevs = callconduit(ui, b'differential.query', {b'ids': [drevid]})
+    for drev in drevs:
+        if int(drev[b'id']) == drevid:
+            return templateutil.hybriddict(
+                {b'url': drev[b'uri'], b'status': drev[b'statusName'],}
+            )
+    return None
+
+
 phabstatus_tmpl = (
     b'{label("changeset.{phase}{if(troubles, \' changeset.troubled\')}", '
     b'shortest(node, 5))} '