diff --git a/src/applications/diffusion/data/DiffusionCommitRef.php b/src/applications/diffusion/data/DiffusionCommitRef.php index 4d6b99d8a6..a3b10c2764 100644 --- a/src/applications/diffusion/data/DiffusionCommitRef.php +++ b/src/applications/diffusion/data/DiffusionCommitRef.php @@ -1,94 +1,114 @@ setCommitterEmail(idx($result, 'committerEmail')) + ->setCommitterName(idx($result, 'committerName')) + ->setAuthorEmail(idx($result, 'authorEmail')) + ->setAuthorName(idx($result, 'authorName')) + ->setMessage(idx($result, 'message')); + + $hashes = array(); + foreach (idx($result, 'hashes', array()) as $hash_result) { + $hashes[] = id(new DiffusionCommitHash()) + ->setHashType(idx($hash_result, 'type')) + ->setHashValue(idx($hash_result, 'value')); + } + + $ref->setHashes($hashes); + + return $ref; + } + public function setHashes(array $hashes) { $this->hashes = $hashes; return $this; } public function getHashes() { return $this->hashes; } public function setCommitterEmail($committer_email) { $this->committerEmail = $committer_email; return $this; } public function getCommitterEmail() { return $this->committerEmail; } public function setCommitterName($committer_name) { $this->committerName = $committer_name; return $this; } public function getCommitterName() { return $this->committerName; } public function setAuthorEmail($author_email) { $this->authorEmail = $author_email; return $this; } public function getAuthorEmail() { return $this->authorEmail; } public function setAuthorName($author_name) { $this->authorName = $author_name; return $this; } public function getAuthorName() { return $this->authorName; } public function setMessage($message) { $this->message = $message; return $this; } public function getMessage() { return $this->message; } public function getAuthor() { return $this->formatUser($this->authorName, $this->authorEmail); } public function getCommitter() { return $this->formatUser($this->committerName, $this->committerEmail); } public function getSummary() { return PhabricatorRepositoryCommitData::summarizeCommitMessage( $this->getMessage()); } private function formatUser($name, $email) { if (strlen($name) && strlen($email)) { return "{$name} <{$email}>"; } else if (strlen($email)) { return $email; } else if (strlen($name)) { return $name; } else { return null; } } } diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php index dc2781ea05..c06cdcd1f4 100644 --- a/src/applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementLookupUsersWorkflow.php @@ -1,97 +1,112 @@ setName('lookup-users') ->setExamples('**lookup-users** __commit__ ...') ->setSynopsis('Resolve user accounts for users attached to __commit__.') ->setArguments( array( array( 'name' => 'commits', 'wildcard' => true, ), )); } public function execute(PhutilArgumentParser $args) { $commits = $this->loadCommits($args, 'commits'); if (!$commits) { throw new PhutilArgumentUsageException( 'Specify one or more commits to resolve users for.'); } $console = PhutilConsole::getConsole(); foreach ($commits as $commit) { $repo = $commit->getRepository(); $name = $repo->formatCommitName($commit->getCommitIdentifier()); $console->writeOut( "%s\n", pht('Examining commit %s...', $name)); - $ref = id(new DiffusionLowLevelCommitQuery()) - ->setRepository($repo) - ->withIdentifier($commit->getCommitIdentifier()) - ->execute(); + $refs_raw = DiffusionQuery::callConduitWithDiffusionRequest( + $this->getViewer(), + DiffusionRequest::newFromDictionary( + array( + 'repository' => $repo, + 'user' => $this->getViewer(), + )), + 'diffusion.querycommits', + array( + 'phids' => array($commit->getPHID()), + 'bypassCache' => true, + )); + + if (empty($refs_raw['data'])) { + throw new Exception( + pht('Unable to retrieve details for commit "%s"!')); + } + + $ref = DiffusionCommitRef::newFromConduitResult(head($refs_raw['data'])); $author = $ref->getAuthor(); $console->writeOut( "%s\n", pht('Raw author string: %s', coalesce($author, 'null'))); if ($author !== null) { $handle = $this->resolveUser($commit, $author); if ($handle) { $console->writeOut( "%s\n", pht('Phabricator user: %s', $handle->getFullName())); } else { $console->writeOut( "%s\n", pht('Unable to resolve a corresponding Phabricator user.')); } } $committer = $ref->getCommitter(); $console->writeOut( "%s\n", pht('Raw committer string: %s', coalesce($committer, 'null'))); if ($committer !== null) { $handle = $this->resolveUser($commit, $committer); if ($handle) { $console->writeOut( "%s\n", pht('Phabricator user: %s', $handle->getFullName())); } else { $console->writeOut( "%s\n", pht('Unable to resolve a corresponding Phabricator user.')); } } } return 0; } private function resolveUser(PhabricatorRepositoryCommit $commit, $name) { $phid = id(new DiffusionResolveUserQuery()) ->withCommit($commit) ->withName($name) ->execute(); if (!$phid) { return null; } return id(new PhabricatorHandleQuery()) ->setViewer($this->getViewer()) ->withPHIDs(array($phid)) ->executeOne(); } }