diff --git a/src/applications/diffusion/query/DiffusionQuery.php b/src/applications/diffusion/query/DiffusionQuery.php --- a/src/applications/diffusion/query/DiffusionQuery.php +++ b/src/applications/diffusion/query/DiffusionQuery.php @@ -73,17 +73,11 @@ $params = $params + $core_params; - $client = $repository->newConduitClient( + $future = $repository->newConduitFuture( $user, + $method, + $params, $drequest->getIsClusterRequest()); - if (!$client) { - $result = id(new ConduitCall($method, $params)) - ->setUser($user) - ->execute(); - $future = new ImmediateFuture($result); - } else { - $future = $client->callMethod($method, $params); - } if (!$return_future) { return $future->resolve(); diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -2258,6 +2258,28 @@ return $client; } + public function newConduitFuture( + PhabricatorUser $viewer, + $method, + array $params, + $never_proxy = false) { + + $client = $this->newConduitClient( + $viewer, + $never_proxy); + + if (!$client) { + $result = id(new ConduitCall($method, $params)) + ->setUser($viewer) + ->execute(); + $future = new ImmediateFuture($result); + } else { + $future = $client->callMethod($method, $params); + } + + return $future; + } + public function getPassthroughEnvironmentalVariables() { $env = $_ENV; diff --git a/src/applications/repository/storage/PhabricatorRepositoryCommit.php b/src/applications/repository/storage/PhabricatorRepositoryCommit.php --- a/src/applications/repository/storage/PhabricatorRepositoryCommit.php +++ b/src/applications/repository/storage/PhabricatorRepositoryCommit.php @@ -523,6 +523,50 @@ return $data->getCommitDetail('committer'); } + public function newCommitRef(PhabricatorUser $viewer) { + $repository = $this->getRepository(); + + $future = $repository->newConduitFuture( + $viewer, + 'internal.commit.search', + array( + 'constraints' => array( + 'repositoryPHIDs' => array($repository->getPHID()), + 'phids' => array($this->getPHID()), + ), + )); + $result = $future->resolve(); + + $commit_display = $this->getMonogram(); + + if (empty($result['data'])) { + throw new Exception( + pht( + 'Unable to retrieve details for commit "%s"!', + $commit_display)); + } + + if (count($result['data']) !== 1) { + throw new Exception( + pht( + 'Got too many results (%s) for commit "%s", expected %s.', + phutil_count($result['data']), + $commit_display, + 1)); + } + + $record = head($result['data']); + $ref_record = idxv($record, array('fields', 'ref')); + + if (!$ref_record) { + throw new Exception( + pht( + 'Unable to retrieve CommitRef record for commit "%s".', + $commit_display)); + } + + return DiffusionCommitRef::newFromDictionary($ref_record); + } /* -( PhabricatorPolicyInterface )----------------------------------------- */ diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php --- a/src/applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitParserWorker.php @@ -124,4 +124,9 @@ return array($link, $suffix); } + + final public function getViewer() { + return PhabricatorUser::getOmnipotentUser(); + } + } diff --git a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php --- a/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php +++ b/src/applications/repository/worker/commitmessageparser/PhabricatorRepositoryCommitMessageParserWorker.php @@ -14,31 +14,10 @@ PhabricatorRepositoryCommit $commit) { if (!$this->shouldSkipImportStep()) { - $viewer = PhabricatorUser::getOmnipotentUser(); - - $refs_raw = DiffusionQuery::callConduitWithDiffusionRequest( - $viewer, - DiffusionRequest::newFromDictionary( - array( - 'repository' => $repository, - 'user' => $viewer, - )), - 'diffusion.querycommits', - array( - 'repositoryPHID' => $repository->getPHID(), - 'phids' => array($commit->getPHID()), - 'bypassCache' => true, - 'needMessages' => true, - )); + $viewer = $this->getViewer(); - if (empty($refs_raw['data'])) { - throw new Exception( - pht( - 'Unable to retrieve details for commit "%s"!', - $commit->getPHID())); - } + $ref = $commit->newCommitRef($viewer); - $ref = DiffusionCommitRef::newFromConduitResult(head($refs_raw['data'])); $this->updateCommitData($ref); }