2012-06-20 21:35:04 +02:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class DifferentialCreateRawDiffConduitAPIMethod
|
|
|
|
extends DifferentialConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'differential.createrawdiff';
|
|
|
|
}
|
2012-06-20 21:35:04 +02:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return pht('Create a new Differential diff from a raw diff source.');
|
2012-06-20 21:35:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function defineParamTypes() {
|
|
|
|
return array(
|
|
|
|
'diff' => 'required string',
|
2014-05-10 03:06:41 +02:00
|
|
|
'repositoryPHID' => 'optional string',
|
2012-06-20 21:35:04 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
|
|
|
return 'nonempty dict';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineErrorTypes() {
|
|
|
|
return array(
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
2014-05-10 03:06:41 +02:00
|
|
|
$viewer = $request->getUser();
|
2012-06-20 21:35:04 +02:00
|
|
|
$raw_diff = $request->getValue('diff');
|
|
|
|
|
2014-05-10 03:06:41 +02:00
|
|
|
$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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 21:35:04 +02:00
|
|
|
$parser = new ArcanistDiffParser();
|
|
|
|
$changes = $parser->parseDiff($raw_diff);
|
|
|
|
$diff = DifferentialDiff::newFromRawChanges($changes);
|
|
|
|
|
2014-11-19 00:32:23 +01:00
|
|
|
$diff_data_dict = array(
|
|
|
|
'creationMethod' => 'web',
|
|
|
|
'authorPHID' => $viewer->getPHID(),
|
|
|
|
'repositoryPHID' => $repository_phid,
|
|
|
|
'lintStatus' => DifferentialLintStatus::LINT_SKIP,
|
|
|
|
'unitStatus' => DifferentialUnitStatus::UNIT_SKIP,);
|
2012-06-20 21:35:04 +02:00
|
|
|
|
2014-11-19 00:32:23 +01:00
|
|
|
$xactions = array(id(new DifferentialTransaction())
|
|
|
|
->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)
|
|
|
|
->setNewValue($diff_data_dict),);
|
2014-05-10 03:06:41 +02:00
|
|
|
|
2014-08-20 23:26:29 +02:00
|
|
|
id(new DifferentialDiffEditor())
|
|
|
|
->setActor($viewer)
|
2014-11-19 00:32:23 +01:00
|
|
|
->setContentSourceFromConduitRequest($request)
|
|
|
|
->applyTransactions($diff, $xactions);
|
2012-06-20 21:35:04 +02:00
|
|
|
|
|
|
|
return $this->buildDiffInfoDictionary($diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|