Patchwork D38: phabricator: allow specifying reviewers on phabsend

login
register
mail settings
Submitter phabricator
Date July 17, 2017, 6:30 p.m.
Message ID <a0eef597f89e4fb8bc768ca885d85cf9@localhost.localdomain>
Download mbox | patch
Permalink /patch/22449/
State Not Applicable
Headers show

Comments

phabricator - July 17, 2017, 6:30 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGb7a75b9a3386: phabricator: allow specifying reviewers on phabsend (authored by quark).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D38?vs=54&id=207

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

AFFECTED FILES
  contrib/phabricator.py

CHANGE DETAILS




EMAIL PREFERENCES
  https://phab.mercurial-scm.org/settings/panel/emailpreferences/

To: quark, durin42, phillco, #hg-reviewers
Cc: phillco, mercurial-devel

Patch

diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -236,14 +236,17 @@ 
     }
     callconduit(ctx.repo(), 'differential.setdiffproperty', params)
 
-def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None):
+def createdifferentialrevision(ctx, revid=None, parentrevid=None, oldnode=None,
+                               actions=None):
     """create or update a Differential Revision
 
     If revid is None, create a new Differential Revision, otherwise update
     revid. If parentrevid is not None, set it as a dependency.
 
     If oldnode is not None, check if the patch content (without commit message
     and metadata) has changed before creating another diff.
+
+    If actions is not None, they will be appended to the transaction.
     """
     repo = ctx.repo()
     if oldnode:
@@ -268,6 +271,9 @@ 
         transactions += [{'type': 'summary', 'value': summary},
                          {'type': 'summary', 'value': ' '}]
 
+    if actions:
+        transactions += actions
+
     # Parse commit message and update related fields.
     desc = ctx.description()
     info = callconduit(repo, 'differential.parsecommitmessage',
@@ -287,8 +293,23 @@ 
 
     return revision
 
+def userphids(repo, names):
+    """convert user names to PHIDs"""
+    query = {'constraints': {'usernames': names}}
+    result = callconduit(repo, 'user.search', query)
+    # username not found is not an error of the API. So check if we have missed
+    # some names here.
+    data = result[r'data']
+    resolved = set(entry[r'fields'][r'username'] for entry in data)
+    unresolved = set(names) - resolved
+    if unresolved:
+        raise error.Abort(_('unknown username: %s')
+                          % ' '.join(sorted(unresolved)))
+    return [entry[r'phid'] for entry in data]
+
 @command('phabsend',
-         [('r', 'rev', [], _('revisions to send'), _('REV'))],
+         [('r', 'rev', [], _('revisions to send'), _('REV')),
+          ('', 'reviewer', [], _('specify reviewers'))],
          _('REV [OPTIONS]'))
 def phabsend(ui, repo, *revs, **opts):
     """upload changesets to Phabricator
@@ -308,6 +329,12 @@ 
     if not revs:
         raise error.Abort(_('phabsend requires at least one changeset'))
 
+    actions = []
+    reviewers = opts.get('reviewer', [])
+    if reviewers:
+        phids = userphids(repo, reviewers)
+        actions.append({'type': 'reviewers.add', 'value': phids})
+
     oldnodedrev = getoldnodedrevmap(repo, [repo[r].node() for r in revs])
 
     # Send patches one by one so we know their Differential Revision IDs and
@@ -322,7 +349,7 @@ 
         if oldnode != ctx.node():
             # Create or update Differential Revision
             revision = createdifferentialrevision(ctx, revid, lastrevid,
-                                                  oldnode)
+                                                  oldnode, actions)
             newrevid = int(revision[r'object'][r'id'])
             if revid:
                 action = _('updated')