diff --git a/src/applications/differential/conduit/ConduitAPI_differential_creatediff_Method.php b/src/applications/differential/conduit/ConduitAPI_differential_creatediff_Method.php index 5ddfbb114d..f0b649b227 100644 --- a/src/applications/differential/conduit/ConduitAPI_differential_creatediff_Method.php +++ b/src/applications/differential/conduit/ConduitAPI_differential_creatediff_Method.php @@ -40,6 +40,7 @@ final class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod { } protected function execute(ConduitAPIRequest $request) { + $viewer = $request->getUser(); $change_data = $request->getValue('changes'); $changes = array(); @@ -53,7 +54,7 @@ final class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod { $diff->setBranch($request->getValue('branch')); $diff->setCreationMethod($request->getValue('creationMethod')); - $diff->setAuthorPHID($request->getUser()->getPHID()); + $diff->setAuthorPHID($viewer->getPHID()); $diff->setBookmark($request->getValue('bookmark')); // TODO: Remove this eventually; for now continue writing the UUID. Note @@ -64,7 +65,7 @@ final class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod { $repository_phid = $request->getValue('repositoryPHID'); if ($repository_phid) { $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($request->getUser()) + ->setViewer($viewer) ->withPHIDs(array($repository_phid)) ->executeOne(); if ($repository) { @@ -142,6 +143,22 @@ final class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod { $diff->save(); + // If we didn't get an explicit `repositoryPHID` (which means the client is + // old, or couldn't figure out which repository the working copy belongs + // to), apply heuristics to try to figure it out. + + if (!$repository_phid) { + $repository = id(new DifferentialRepositoryLookup()) + ->setDiff($diff) + ->setViewer($viewer) + ->lookupRepository(); + if ($repository) { + $diff->setRepositoryPHID($repository->getPHID()); + $diff->setRepositoryUUID($repository->getUUID()); + $diff->save(); + } + } + $path = '/differential/diff/'.$diff->getID().'/'; $uri = PhabricatorEnv::getURI($path); diff --git a/src/applications/differential/editor/DifferentialTransactionEditor.php b/src/applications/differential/editor/DifferentialTransactionEditor.php index 23f77301b1..5f4483b7b3 100644 --- a/src/applications/differential/editor/DifferentialTransactionEditor.php +++ b/src/applications/differential/editor/DifferentialTransactionEditor.php @@ -498,6 +498,7 @@ final class DifferentialTransactionEditor $object->setLineCount($diff->getLineCount()); $object->setRepositoryPHID($diff->getRepositoryPHID()); + $object->setArcanistProjectPHID($diff->getArcanistProjectPHID()); return; } diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php index a7f95e28e6..52f22f91a0 100644 --- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php @@ -157,28 +157,10 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter { public function loadRepository() { if ($this->repository === null) { $this->repository = false; - - $viewer = PhabricatorUser::getOmnipotentUser(); - $repository_phid = null; - - $revision = $this->revision; - if ($revision->getRepositoryPHID()) { - $repository_phid = $revision->getRepositoryPHID(); - } else { - $repository = id(new DifferentialRepositoryLookup()) - ->setViewer($viewer) - ->setDiff($this->diff) - ->lookupRepository(); - if ($repository) { - // We want to get the projects for this repository too, so run a - // full query for it below. - $repository_phid = $repository->getPHID(); - } - } - + $repository_phid = $this->getObject()->getRepositoryPHID(); if ($repository_phid) { $repository = id(new PhabricatorRepositoryQuery()) - ->setViewer($viewer) + ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withPHIDs(array($repository_phid)) ->needProjectPHIDs(true) ->executeOne();