Differential D14428 Diff 34932 src/applications/diffusion/conduit/DiffusionUpdateCoverageConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionUpdateCoverageConduitAPIMethod.php
Show All 14 Lines | public function getMethodDescription() { | ||||
return pht('Publish coverage information for a repository.'); | return pht('Publish coverage information for a repository.'); | ||||
} | } | ||||
protected function defineReturnType() { | protected function defineReturnType() { | ||||
return 'void'; | return 'void'; | ||||
} | } | ||||
protected function defineParamTypes() { | protected function defineParamTypes() { | ||||
$modes = array( | |||||
'overwrite', | |||||
'update', | |||||
); | |||||
return array( | return array( | ||||
'repositoryPHID' => 'required phid', | 'repositoryPHID' => 'required phid', | ||||
'branch' => 'required string', | 'branch' => 'required string', | ||||
'commit' => 'required string', | 'commit' => 'required string', | ||||
'coverage' => 'required map<string, string>', | 'coverage' => 'required map<string, string>', | ||||
'mode' => 'optional '.$this->formatStringConstants($modes), | |||||
); | ); | ||||
} | } | ||||
protected function execute(ConduitAPIRequest $request) { | protected function execute(ConduitAPIRequest $request) { | ||||
$viewer = $request->getUser(); | $viewer = $request->getUser(); | ||||
$repository_phid = $request->getValue('repositoryPHID'); | $repository_phid = $request->getValue('repositoryPHID'); | ||||
$repository = id(new PhabricatorRepositoryQuery()) | $repository = id(new PhabricatorRepositoryQuery()) | ||||
Show All 36 Lines | foreach ($coverage as $path => $coverage_info) { | ||||
$path_map[$path], | $path_map[$path], | ||||
$commit->getID(), | $commit->getID(), | ||||
$coverage_info); | $coverage_info); | ||||
} | } | ||||
$table_name = 'repository_coverage'; | $table_name = 'repository_coverage'; | ||||
$conn->openTransaction(); | $conn->openTransaction(); | ||||
$mode = $request->getValue('mode'); | |||||
switch ($mode) { | |||||
case '': | |||||
case 'overwrite': | |||||
// sets the coverage for the whole branch, deleting all previous | |||||
// coverage information | |||||
queryfx( | queryfx( | ||||
$conn, | $conn, | ||||
'DELETE FROM %T WHERE branchID = %d', | 'DELETE FROM %T WHERE branchID = %d', | ||||
$table_name, | $table_name, | ||||
$branch->getID()); | $branch->getID()); | ||||
break; | |||||
case 'update': | |||||
// sets the coverage for the provided files on the specified commit | |||||
break; | |||||
default: | |||||
$conn->killTransaction(); | |||||
throw new Exception(pht('Invalid mode "%s".', $mode)); | |||||
} | |||||
foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { | foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { | ||||
queryfx( | queryfx( | ||||
$conn, | $conn, | ||||
'INSERT INTO %T (branchID, pathID, commitID, coverage) VALUES %Q', | 'INSERT INTO %T (branchID, pathID, commitID, coverage) VALUES %Q'. | ||||
' ON DUPLICATE KEY UPDATE coverage=VALUES(coverage)', | |||||
$table_name, | $table_name, | ||||
$chunk); | $chunk); | ||||
} | } | ||||
$conn->saveTransaction(); | $conn->saveTransaction(); | ||||
} | } | ||||
} | } |