1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-20 10:48:40 +01:00

Add 'repositoryPHID' to 'differential.createrawdiff'

Summary:
See <https://github.com/facebook/phabricator/issues/596>

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
This commit is contained in:
epriestley 2014-05-09 18:06:41 -07:00
parent 9d0d1ac42f
commit 997c8591b2

View file

@ -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);