[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/repository/management/ -> PhabricatorRepositoryManagementLookupUsersWorkflow.php (source)

   1  <?php
   2  
   3  final class PhabricatorRepositoryManagementLookupUsersWorkflow
   4    extends PhabricatorRepositoryManagementWorkflow {
   5  
   6    public function didConstruct() {
   7      $this
   8        ->setName('lookup-users')
   9        ->setExamples('**lookup-users** __commit__ ...')
  10        ->setSynopsis('Resolve user accounts for users attached to __commit__.')
  11        ->setArguments(
  12          array(
  13            array(
  14              'name'        => 'commits',
  15              'wildcard'    => true,
  16            ),
  17          ));
  18    }
  19  
  20    public function execute(PhutilArgumentParser $args) {
  21      $commits = $this->loadCommits($args, 'commits');
  22      if (!$commits) {
  23        throw new PhutilArgumentUsageException(
  24          'Specify one or more commits to resolve users for.');
  25      }
  26  
  27      $console = PhutilConsole::getConsole();
  28      foreach ($commits as $commit) {
  29        $repo = $commit->getRepository();
  30        $name =  $repo->formatCommitName($commit->getCommitIdentifier());
  31  
  32        $console->writeOut(
  33          "%s\n",
  34          pht('Examining commit %s...', $name));
  35  
  36        $ref = id(new DiffusionLowLevelCommitQuery())
  37          ->setRepository($repo)
  38          ->withIdentifier($commit->getCommitIdentifier())
  39          ->execute();
  40  
  41        $author = $ref->getAuthor();
  42        $console->writeOut(
  43          "%s\n",
  44          pht('Raw author string: %s', coalesce($author, 'null')));
  45  
  46        if ($author !== null) {
  47          $handle = $this->resolveUser($commit, $author);
  48          if ($handle) {
  49            $console->writeOut(
  50              "%s\n",
  51              pht('Phabricator user: %s', $handle->getFullName()));
  52          } else {
  53            $console->writeOut(
  54              "%s\n",
  55              pht('Unable to resolve a corresponding Phabricator user.'));
  56          }
  57        }
  58  
  59        $committer = $ref->getCommitter();
  60        $console->writeOut(
  61          "%s\n",
  62          pht('Raw committer string: %s', coalesce($committer, 'null')));
  63  
  64        if ($committer !== null) {
  65          $handle = $this->resolveUser($commit, $committer);
  66          if ($handle) {
  67            $console->writeOut(
  68              "%s\n",
  69              pht('Phabricator user: %s', $handle->getFullName()));
  70          } else {
  71            $console->writeOut(
  72              "%s\n",
  73              pht('Unable to resolve a corresponding Phabricator user.'));
  74          }
  75        }
  76      }
  77  
  78      return 0;
  79    }
  80  
  81    private function resolveUser(PhabricatorRepositoryCommit $commit, $name) {
  82      $phid = id(new DiffusionResolveUserQuery())
  83        ->withCommit($commit)
  84        ->withName($name)
  85        ->execute();
  86  
  87      if (!$phid) {
  88        return null;
  89      }
  90  
  91      return id(new PhabricatorHandleQuery())
  92        ->setViewer($this->getViewer())
  93        ->withPHIDs(array($phid))
  94        ->executeOne();
  95    }
  96  
  97  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1