From 997c8591b27fac69d12cd1ca0e648e8916d1d24f Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 9 May 2014 18:06:41 -0700 Subject: [PATCH] Add 'repositoryPHID' to 'differential.createrawdiff' Summary: See Broadly, Facebook would like to bring Pull Requests from GitHub into Phabricator. In the long term we can do this properly via Doorkeeper/Nuance, but that's probably a ways off. This seems like a reasonable low-budget compromise for now. I'm a little hesitant to add a ton of parameters to this call, but `repositoryPHID` seems pretty reasonable, and is notable because it also controls default policies. Test Plan: - Created a diff with no repositoryPHID. - Created a diff with a repositoryPHID. - Verified it carried over when the diff was used to create a revision. Reviewers: btrahan Reviewed By: btrahan Subscribers: ptarjan, jamesgpearce, epriestley Differential Revision: https://secure.phabricator.com/D9023 --- ...tAPI_differential_createrawdiff_Method.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/applications/differential/conduit/ConduitAPI_differential_createrawdiff_Method.php b/src/applications/differential/conduit/ConduitAPI_differential_createrawdiff_Method.php index eff49c60a3..05f71da352 100644 --- a/src/applications/differential/conduit/ConduitAPI_differential_createrawdiff_Method.php +++ b/src/applications/differential/conduit/ConduitAPI_differential_createrawdiff_Method.php @@ -4,12 +4,13 @@ final class ConduitAPI_differential_createrawdiff_Method extends ConduitAPI_differential_Method { public function getMethodDescription() { - return "Create a new Differential diff from a raw diff source."; + return pht("Create a new Differential diff from a raw diff source."); } public function defineParamTypes() { return array( 'diff' => 'required string', + 'repositoryPHID' => 'optional string', ); } @@ -23,8 +24,23 @@ final class ConduitAPI_differential_createrawdiff_Method } protected function execute(ConduitAPIRequest $request) { + $viewer = $request->getUser(); $raw_diff = $request->getValue('diff'); + $repository_phid = $request->getValue('repositoryPHID'); + if ($repository_phid) { + $repository = id(new PhabricatorRepositoryQuery()) + ->setViewer($viewer) + ->withPHIDs(array($repository_phid)) + ->executeOne(); + if (!$repository) { + throw new Exception( + pht('No such repository "%s"!', $repository_phid)); + } + } else { + $repository = null; + } + $parser = new ArcanistDiffParser(); $changes = $parser->parseDiff($raw_diff); $diff = DifferentialDiff::newFromRawChanges($changes); @@ -32,8 +48,13 @@ final class ConduitAPI_differential_createrawdiff_Method $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); $diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP); - $diff->setAuthorPHID($request->getUser()->getPHID()); + $diff->setAuthorPHID($viewer->getPHID()); $diff->setCreationMethod('web'); + + if ($repository) { + $diff->setRepositoryPHID($repository->getPHID()); + } + $diff->save(); return $this->buildDiffInfoDictionary($diff);