2011-01-24 20:01:53 +01: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 DifferentialCreateDiffConduitAPIMethod
|
|
|
|
extends DifferentialConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'differential.creatediff';
|
|
|
|
}
|
2011-01-24 20:01:53 +01:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return 'Create a new Differential diff.';
|
2011-01-24 20:01:53 +01:00
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineParamTypes() {
|
2014-05-15 06:59:03 +02:00
|
|
|
|
|
|
|
$vcs_const = $this->formatStringConstants(
|
|
|
|
array(
|
|
|
|
'svn',
|
|
|
|
'git',
|
|
|
|
'hg',
|
|
|
|
));
|
|
|
|
|
|
|
|
$status_const = $this->formatStringConstants(
|
|
|
|
array(
|
|
|
|
'none',
|
|
|
|
'skip',
|
|
|
|
'okay',
|
|
|
|
'warn',
|
|
|
|
'fail',
|
|
|
|
'postponed',
|
|
|
|
));
|
|
|
|
|
2011-01-24 20:01:53 +01:00
|
|
|
return array(
|
|
|
|
'changes' => 'required list<dict>',
|
|
|
|
'sourceMachine' => 'required string',
|
|
|
|
'sourcePath' => 'required string',
|
|
|
|
'branch' => 'required string',
|
2012-06-30 23:45:30 +02:00
|
|
|
'bookmark' => 'optional string',
|
2014-05-15 06:59:03 +02:00
|
|
|
'sourceControlSystem' => 'required '.$vcs_const,
|
2011-01-24 20:01:53 +01:00
|
|
|
'sourceControlPath' => 'required string',
|
|
|
|
'sourceControlBaseRevision' => 'required string',
|
|
|
|
'creationMethod' => 'optional string',
|
|
|
|
'arcanistProject' => 'optional string',
|
2014-05-15 06:59:03 +02:00
|
|
|
'lintStatus' => 'required '.$status_const,
|
|
|
|
'unitStatus' => 'required '.$status_const,
|
2014-01-27 00:29:22 +01:00
|
|
|
'repositoryPHID' => 'optional phid',
|
|
|
|
|
|
|
|
'parentRevisionID' => 'deprecated',
|
|
|
|
'authorPHID' => 'deprecated',
|
|
|
|
'repositoryUUID' => 'deprecated',
|
2011-01-24 20:01:53 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineReturnType() {
|
2011-01-24 20:01:53 +01:00
|
|
|
return 'nonempty dict';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
2014-03-21 22:39:56 +01:00
|
|
|
$viewer = $request->getUser();
|
2011-01-24 20:01:53 +01:00
|
|
|
$change_data = $request->getValue('changes');
|
|
|
|
|
|
|
|
$changes = array();
|
|
|
|
foreach ($change_data as $dict) {
|
|
|
|
$changes[] = ArcanistDiffChange::newFromDictionary($dict);
|
|
|
|
}
|
|
|
|
|
2014-11-19 21:16:07 +01:00
|
|
|
$diff = DifferentialDiff::newFromRawChanges($viewer, $changes);
|
2011-01-24 20:01:53 +01:00
|
|
|
|
2014-11-19 00:32:23 +01:00
|
|
|
// TODO: Remove repository UUID eventually; for now continue writing
|
|
|
|
// the UUID. Note that we'll overwrite it below if we identify a
|
|
|
|
// repository, and `arc` no longer sends it. This stuff is retained for
|
|
|
|
// backward compatibility.
|
2014-01-27 00:29:22 +01:00
|
|
|
|
2014-11-19 00:32:23 +01:00
|
|
|
$repository_uuid = $request->getValue('repositoryUUID');
|
2014-01-27 00:29:22 +01:00
|
|
|
$repository_phid = $request->getValue('repositoryPHID');
|
|
|
|
if ($repository_phid) {
|
|
|
|
$repository = id(new PhabricatorRepositoryQuery())
|
2014-03-21 22:39:56 +01:00
|
|
|
->setViewer($viewer)
|
2014-01-27 00:29:22 +01:00
|
|
|
->withPHIDs(array($repository_phid))
|
|
|
|
->executeOne();
|
|
|
|
if ($repository) {
|
2014-11-19 00:32:23 +01:00
|
|
|
$repository_phid = $repository->getPHID();
|
|
|
|
$repository_uuid = $repository->getUUID();
|
2011-01-24 20:01:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-06 05:49:31 +02:00
|
|
|
$project_name = $request->getValue('arcanistProject');
|
|
|
|
$project_phid = null;
|
|
|
|
if ($project_name) {
|
|
|
|
$arcanist_project = id(new PhabricatorRepositoryArcanistProject())
|
|
|
|
->loadOneWhere(
|
|
|
|
'name = %s',
|
|
|
|
$project_name);
|
|
|
|
if (!$arcanist_project) {
|
|
|
|
$arcanist_project = new PhabricatorRepositoryArcanistProject();
|
|
|
|
$arcanist_project->setName($project_name);
|
|
|
|
$arcanist_project->save();
|
|
|
|
}
|
|
|
|
$project_phid = $arcanist_project->getPHID();
|
|
|
|
}
|
|
|
|
|
2011-01-24 20:01:53 +01:00
|
|
|
switch ($request->getValue('lintStatus')) {
|
|
|
|
case 'skip':
|
2014-11-19 00:32:23 +01:00
|
|
|
$lint_status = DifferentialLintStatus::LINT_SKIP;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
|
|
|
case 'okay':
|
2014-11-19 00:32:23 +01:00
|
|
|
$lint_status = DifferentialLintStatus::LINT_OKAY;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
|
|
|
case 'warn':
|
2014-11-19 00:32:23 +01:00
|
|
|
$lint_status = DifferentialLintStatus::LINT_WARN;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
|
|
|
case 'fail':
|
2014-11-19 00:32:23 +01:00
|
|
|
$lint_status = DifferentialLintStatus::LINT_FAIL;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
2012-07-06 04:39:30 +02:00
|
|
|
case 'postponed':
|
2014-11-19 00:32:23 +01:00
|
|
|
$lint_status = DifferentialLintStatus::LINT_POSTPONED;
|
2012-07-06 04:39:30 +02:00
|
|
|
break;
|
2011-01-24 20:01:53 +01:00
|
|
|
case 'none':
|
|
|
|
default:
|
2014-11-19 00:32:23 +01:00
|
|
|
$lint_status = DifferentialLintStatus::LINT_NONE;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($request->getValue('unitStatus')) {
|
|
|
|
case 'skip':
|
2014-11-19 00:32:23 +01:00
|
|
|
$unit_status = DifferentialUnitStatus::UNIT_SKIP;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
|
|
|
case 'okay':
|
2014-11-19 00:32:23 +01:00
|
|
|
$unit_status = DifferentialUnitStatus::UNIT_OKAY;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
|
|
|
case 'warn':
|
2014-11-19 00:32:23 +01:00
|
|
|
$unit_status = DifferentialUnitStatus::UNIT_WARN;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
|
|
|
case 'fail':
|
2014-11-19 00:32:23 +01:00
|
|
|
$unit_status = DifferentialUnitStatus::UNIT_FAIL;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
2011-06-09 01:16:59 +02:00
|
|
|
case 'postponed':
|
2014-11-19 00:32:23 +01:00
|
|
|
$unit_status = DifferentialUnitStatus::UNIT_POSTPONED;
|
2011-06-09 01:16:59 +02:00
|
|
|
break;
|
2011-01-24 20:01:53 +01:00
|
|
|
case 'none':
|
|
|
|
default:
|
2014-11-19 00:32:23 +01:00
|
|
|
$unit_status = DifferentialUnitStatus::UNIT_NONE;
|
2011-01-24 20:01:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-19 00:32:23 +01:00
|
|
|
$diff_data_dict = array(
|
|
|
|
'sourcePath' => $request->getValue('sourcePath'),
|
|
|
|
'sourceMachine' => $request->getValue('sourceMachine'),
|
|
|
|
'branch' => $request->getValue('branch'),
|
|
|
|
'creationMethod' => $request->getValue('creationMethod'),
|
|
|
|
'authorPHID' => $viewer->getPHID(),
|
|
|
|
'bookmark' => $request->getValue('bookmark'),
|
|
|
|
'repositoryUUID' => $repository_uuid,
|
|
|
|
'repositoryPHID' => $repository_phid,
|
|
|
|
'sourceControlSystem' => $request->getValue('sourceControlSystem'),
|
|
|
|
'sourceControlPath' => $request->getValue('sourceControlPath'),
|
|
|
|
'sourceControlBaseRevision' =>
|
|
|
|
$request->getValue('sourceControlBaseRevision'),
|
|
|
|
'arcanistProjectPHID' => $project_phid,
|
|
|
|
'lintStatus' => $lint_status,
|
2015-04-05 14:29:39 +02:00
|
|
|
'unitStatus' => $unit_status,
|
|
|
|
);
|
2014-11-19 00:32:23 +01:00
|
|
|
|
|
|
|
$xactions = array(id(new DifferentialTransaction())
|
|
|
|
->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)
|
2015-04-05 14:29:39 +02:00
|
|
|
->setNewValue($diff_data_dict),
|
|
|
|
);
|
2014-11-19 00:32:23 +01:00
|
|
|
|
2014-08-20 23:26:29 +02:00
|
|
|
id(new DifferentialDiffEditor())
|
|
|
|
->setActor($viewer)
|
2014-11-19 00:32:23 +01:00
|
|
|
->setContentSourceFromConduitRequest($request)
|
2014-12-01 21:13:04 +01:00
|
|
|
->setContinueOnNoEffect(true)
|
2014-11-19 00:32:23 +01:00
|
|
|
->applyTransactions($diff, $xactions);
|
2014-03-21 22:39:56 +01:00
|
|
|
|
2011-02-01 01:59:01 +01:00
|
|
|
$path = '/differential/diff/'.$diff->getID().'/';
|
|
|
|
$uri = PhabricatorEnv::getURI($path);
|
|
|
|
|
2011-01-24 20:01:53 +01:00
|
|
|
return array(
|
|
|
|
'diffid' => $diff->getID(),
|
2011-02-01 01:59:01 +01:00
|
|
|
'uri' => $uri,
|
2011-01-24 20:01:53 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|