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:
@@ -4,12 +4,13 @@ final class ConduitAPI_differential_createrawdiff_Method
|
|||||||
extends ConduitAPI_differential_Method {
|
extends ConduitAPI_differential_Method {
|
||||||
|
|
||||||
public function getMethodDescription() {
|
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() {
|
public function defineParamTypes() {
|
||||||
return array(
|
return array(
|
||||||
'diff' => 'required string',
|
'diff' => 'required string',
|
||||||
|
'repositoryPHID' => 'optional string',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,8 +24,23 @@ final class ConduitAPI_differential_createrawdiff_Method
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(ConduitAPIRequest $request) {
|
protected function execute(ConduitAPIRequest $request) {
|
||||||
|
$viewer = $request->getUser();
|
||||||
$raw_diff = $request->getValue('diff');
|
$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();
|
$parser = new ArcanistDiffParser();
|
||||||
$changes = $parser->parseDiff($raw_diff);
|
$changes = $parser->parseDiff($raw_diff);
|
||||||
$diff = DifferentialDiff::newFromRawChanges($changes);
|
$diff = DifferentialDiff::newFromRawChanges($changes);
|
||||||
@@ -32,8 +48,13 @@ final class ConduitAPI_differential_createrawdiff_Method
|
|||||||
$diff->setLintStatus(DifferentialLintStatus::LINT_SKIP);
|
$diff->setLintStatus(DifferentialLintStatus::LINT_SKIP);
|
||||||
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP);
|
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP);
|
||||||
|
|
||||||
$diff->setAuthorPHID($request->getUser()->getPHID());
|
$diff->setAuthorPHID($viewer->getPHID());
|
||||||
$diff->setCreationMethod('web');
|
$diff->setCreationMethod('web');
|
||||||
|
|
||||||
|
if ($repository) {
|
||||||
|
$diff->setRepositoryPHID($repository->getPHID());
|
||||||
|
}
|
||||||
|
|
||||||
$diff->save();
|
$diff->save();
|
||||||
|
|
||||||
return $this->buildDiffInfoDictionary($diff);
|
return $this->buildDiffInfoDictionary($diff);
|
||||||
|
|||||||
Reference in New Issue
Block a user