1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-01 03:02:43 +01:00
phorge-phorge/src/applications/diffusion/conduit/DiffusionGetLintMessagesConduitAPIMethod.php
Joshua Spence f8b7f03145 Change "lint save" to not use Arcanist Projects
Summary: Ref T7604. Change `DiffusionLintSaveRunner` to use repositories instead of Arcanist Projects.

Test Plan: Ran the `save_lint.php` script and queried results using the `diffusion.getlintmessages` Conduit endpoint.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T7604

Differential Revision: https://secure.phabricator.com/D12893
2015-05-19 00:07:47 +10:00

75 lines
2.1 KiB
PHP

<?php
final class DiffusionGetLintMessagesConduitAPIMethod
extends DiffusionConduitAPIMethod {
public function getAPIMethodName() {
return 'diffusion.getlintmessages';
}
public function getMethodStatus() {
return self::METHOD_STATUS_UNSTABLE;
}
public function getMethodDescription() {
return pht('Get lint messages for existing code.');
}
protected function defineParamTypes() {
return array(
'repositoryPHID' => 'required phid',
'branch' => 'required string',
'commit' => 'optional string',
'files' => 'required list<string>',
);
}
protected function defineReturnType() {
return 'list<dict>';
}
protected function execute(ConduitAPIRequest $request) {
$viewer = $request->getUser();
$repository_phid = $request->getValue('repositoryPHID');
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->withPHIDs(array($repository_phid))
->executeOne();
if (!$repository) {
throw new Exception(
pht('No repository exists with PHID "%s".', $repository_phid));
}
$branch_name = $request->getValue('branch');
if ($branch_name == '') {
$repository = id(new PhabricatorRepositoryQuery())
->setViewer($request->getUser())
->withIDs(array($repository->getID()))
->executeOne();
$branch_name = $repository->getDefaultArcanistBranch();
}
$branch = id(new PhabricatorRepositoryBranch())->loadOneWhere(
'repositoryID = %d AND name = %s',
$repository->getID(),
$branch_name);
if (!$branch || !$branch->getLintCommit()) {
return array();
}
$lint_messages = queryfx_all(
$branch->establishConnection('r'),
'SELECT path, line, code FROM %T WHERE branchID = %d AND path IN (%Ls)',
PhabricatorRepository::TABLE_LINTMESSAGE,
$branch->getID(),
$request->getValue('files'));
// TODO: Compare commit identifiers of individual files like in
// DiffusionBrowseFileController::loadLintMessages().
return $lint_messages;
}
}