Differential D12893 Diff 31026 src/applications/diffusion/conduit/DiffusionGetLintMessagesConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/conduit/DiffusionGetLintMessagesConduitAPIMethod.php
| <?php | <?php | ||||
| final class DiffusionGetLintMessagesConduitAPIMethod | final class DiffusionGetLintMessagesConduitAPIMethod | ||||
| extends DiffusionConduitAPIMethod { | extends DiffusionConduitAPIMethod { | ||||
| public function getAPIMethodName() { | public function getAPIMethodName() { | ||||
| return 'diffusion.getlintmessages'; | return 'diffusion.getlintmessages'; | ||||
| } | } | ||||
| public function getMethodStatus() { | public function getMethodStatus() { | ||||
| return self::METHOD_STATUS_UNSTABLE; | return self::METHOD_STATUS_UNSTABLE; | ||||
| } | } | ||||
| public function getMethodDescription() { | public function getMethodDescription() { | ||||
| return 'Get lint messages for existing code.'; | return pht('Get lint messages for existing code.'); | ||||
| } | } | ||||
| protected function defineParamTypes() { | protected function defineParamTypes() { | ||||
| return array( | return array( | ||||
| 'arcanistProject' => 'required string', | 'repositoryPHID' => 'required phid', | ||||
| 'branch' => 'optional string', | 'branch' => 'required string', | ||||
| 'commit' => 'optional string', | 'commit' => 'optional string', | ||||
| 'files' => 'required list<string>', | 'files' => 'required list<string>', | ||||
| ); | ); | ||||
| } | } | ||||
| protected function defineReturnType() { | protected function defineReturnType() { | ||||
| return 'list<dict>'; | return 'list<dict>'; | ||||
| } | } | ||||
| protected function execute(ConduitAPIRequest $request) { | protected function execute(ConduitAPIRequest $request) { | ||||
| $project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere( | $viewer = $request->getUser(); | ||||
| 'name = %s', | |||||
| $request->getValue('arcanistProject')); | $repository_phid = $request->getValue('repositoryPHID'); | ||||
| if (!$project || !$project->getRepositoryID()) { | $repository = id(new PhabricatorRepositoryQuery()) | ||||
| return array(); | ->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'); | $branch_name = $request->getValue('branch'); | ||||
| if ($branch_name == '') { | if ($branch_name == '') { | ||||
| $repository = id(new PhabricatorRepositoryQuery()) | $repository = id(new PhabricatorRepositoryQuery()) | ||||
| ->setViewer($request->getUser()) | ->setViewer($request->getUser()) | ||||
| ->withIDs(array($project->getRepositoryID())) | ->withIDs(array($repository->getID())) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| $branch_name = $repository->getDefaultArcanistBranch(); | $branch_name = $repository->getDefaultArcanistBranch(); | ||||
| } | } | ||||
| $branch = id(new PhabricatorRepositoryBranch())->loadOneWhere( | $branch = id(new PhabricatorRepositoryBranch())->loadOneWhere( | ||||
| 'repositoryID = %d AND name = %s', | 'repositoryID = %d AND name = %s', | ||||
| $project->getRepositoryID(), | $repository->getID(), | ||||
| $branch_name); | $branch_name); | ||||
| if (!$branch || !$branch->getLintCommit()) { | if (!$branch || !$branch->getLintCommit()) { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| $lint_messages = queryfx_all( | $lint_messages = queryfx_all( | ||||
| $branch->establishConnection('r'), | $branch->establishConnection('r'), | ||||
| 'SELECT path, line, code FROM %T WHERE branchID = %d AND path IN (%Ls)', | 'SELECT path, line, code FROM %T WHERE branchID = %d AND path IN (%Ls)', | ||||
| Show All 11 Lines | |||||