1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 03:50:54 +01:00
phorge-phorge/src/applications/differential/conduit/DifferentialCreateDiffConduitAPIMethod.php

187 lines
5.7 KiB
PHP
Raw Normal View History

2011-01-24 20:01:53 +01:00
<?php
final class DifferentialCreateDiffConduitAPIMethod
extends DifferentialConduitAPIMethod {
public function getAPIMethodName() {
return 'differential.creatediff';
}
2011-01-24 20:01:53 +01:00
public function getMethodDescription() {
return 'Create a new Differential diff.';
2011-01-24 20:01:53 +01:00
}
public function defineParamTypes() {
$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',
'bookmark' => 'optional string',
'sourceControlSystem' => 'required '.$vcs_const,
2011-01-24 20:01:53 +01:00
'sourceControlPath' => 'required string',
'sourceControlBaseRevision' => 'required string',
'creationMethod' => 'optional string',
'arcanistProject' => 'optional string',
'lintStatus' => 'required '.$status_const,
'unitStatus' => 'required '.$status_const,
'repositoryPHID' => 'optional phid',
'parentRevisionID' => 'deprecated',
'authorPHID' => 'deprecated',
'repositoryUUID' => 'deprecated',
2011-01-24 20:01:53 +01:00
);
}
public function defineReturnType() {
return 'nonempty dict';
}
public function defineErrorTypes() {
return array(
);
}
protected function execute(ConduitAPIRequest $request) {
$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);
}
$diff = DifferentialDiff::newFromRawChanges($changes);
// 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.
$repository_uuid = $request->getValue('repositoryUUID');
$repository_phid = $request->getValue('repositoryPHID');
if ($repository_phid) {
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withPHIDs(array($repository_phid))
->executeOne();
if ($repository) {
$repository_phid = $repository->getPHID();
$repository_uuid = $repository->getUUID();
2011-01-24 20:01:53 +01: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':
$lint_status = DifferentialLintStatus::LINT_SKIP;
2011-01-24 20:01:53 +01:00
break;
case 'okay':
$lint_status = DifferentialLintStatus::LINT_OKAY;
2011-01-24 20:01:53 +01:00
break;
case 'warn':
$lint_status = DifferentialLintStatus::LINT_WARN;
2011-01-24 20:01:53 +01:00
break;
case 'fail':
$lint_status = DifferentialLintStatus::LINT_FAIL;
2011-01-24 20:01:53 +01:00
break;
case 'postponed':
$lint_status = DifferentialLintStatus::LINT_POSTPONED;
break;
2011-01-24 20:01:53 +01:00
case 'none':
default:
$lint_status = DifferentialLintStatus::LINT_NONE;
2011-01-24 20:01:53 +01:00
break;
}
switch ($request->getValue('unitStatus')) {
case 'skip':
$unit_status = DifferentialUnitStatus::UNIT_SKIP;
2011-01-24 20:01:53 +01:00
break;
case 'okay':
$unit_status = DifferentialUnitStatus::UNIT_OKAY;
2011-01-24 20:01:53 +01:00
break;
case 'warn':
$unit_status = DifferentialUnitStatus::UNIT_WARN;
2011-01-24 20:01:53 +01:00
break;
case 'fail':
$unit_status = DifferentialUnitStatus::UNIT_FAIL;
2011-01-24 20:01:53 +01:00
break;
case 'postponed':
$unit_status = DifferentialUnitStatus::UNIT_POSTPONED;
break;
2011-01-24 20:01:53 +01:00
case 'none':
default:
$unit_status = DifferentialUnitStatus::UNIT_NONE;
2011-01-24 20:01:53 +01:00
break;
}
$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,
'unitStatus' => $unit_status,);
$xactions = array(id(new DifferentialTransaction())
->setTransactionType(DifferentialDiffTransaction::TYPE_DIFF_CREATE)
->setNewValue($diff_data_dict),);
id(new DifferentialDiffEditor())
->setActor($viewer)
->setContentSourceFromConduitRequest($request)
->applyTransactions($diff, $xactions);
$path = '/differential/diff/'.$diff->getID().'/';
$uri = PhabricatorEnv::getURI($path);
2011-01-24 20:01:53 +01:00
return array(
'diffid' => $diff->getID(),
'uri' => $uri,
2011-01-24 20:01:53 +01:00
);
}
}