From 493196e16a6f8989e8f097ce8324d71260097da0 Mon Sep 17 00:00:00 2001 From: vrana Date: Thu, 8 Nov 2012 17:16:23 -0800 Subject: [PATCH] Add Conduit method for getting Diffusion lint messages Test Plan: /conduit/method/diffusion.getlintmessages/, ran it, saw results. Reviewers: epriestley, wez Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2038 Differential Revision: https://secure.phabricator.com/D3932 --- src/__phutil_library_map__.php | 2 + ...itAPI_diffusion_getlintmessages_Method.php | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/applications/conduit/method/diffusion/ConduitAPI_diffusion_getlintmessages_Method.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a4a1457121..5a86c6b01a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -139,6 +139,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_updateunitresults_Method' => 'applications/conduit/method/differential/ConduitAPI_differential_updateunitresults_Method.php', 'ConduitAPI_diffusion_findsymbols_Method' => 'applications/conduit/method/diffusion/ConduitAPI_diffusion_findsymbols_Method.php', 'ConduitAPI_diffusion_getcommits_Method' => 'applications/conduit/method/diffusion/ConduitAPI_diffusion_getcommits_Method.php', + 'ConduitAPI_diffusion_getlintmessages_Method' => 'applications/conduit/method/diffusion/ConduitAPI_diffusion_getlintmessages_Method.php', 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/conduit/method/diffusion/ConduitAPI_diffusion_getrecentcommitsbypath_Method.php', 'ConduitAPI_feed_publish_Method' => 'applications/conduit/method/feed/ConduitAPI_feed_publish_Method.php', 'ConduitAPI_feed_query_Method' => 'applications/conduit/method/feed/ConduitAPI_feed_query_Method.php', @@ -1428,6 +1429,7 @@ phutil_register_library_map(array( 'ConduitAPI_differential_updateunitresults_Method' => 'ConduitAPIMethod', 'ConduitAPI_diffusion_findsymbols_Method' => 'ConduitAPIMethod', 'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPIMethod', + 'ConduitAPI_diffusion_getlintmessages_Method' => 'ConduitAPIMethod', 'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPIMethod', 'ConduitAPI_feed_publish_Method' => 'ConduitAPIMethod', 'ConduitAPI_feed_query_Method' => 'ConduitAPIMethod', diff --git a/src/applications/conduit/method/diffusion/ConduitAPI_diffusion_getlintmessages_Method.php b/src/applications/conduit/method/diffusion/ConduitAPI_diffusion_getlintmessages_Method.php new file mode 100644 index 0000000000..28e213502f --- /dev/null +++ b/src/applications/conduit/method/diffusion/ConduitAPI_diffusion_getlintmessages_Method.php @@ -0,0 +1,71 @@ + 'required string', + 'branch' => 'optional string', + 'commit' => 'optional string', + 'files' => 'required list', + ); + } + + public function defineReturnType() { + return 'list'; + } + + public function defineErrorTypes() { + return array( + ); + } + + protected function execute(ConduitAPIRequest $request) { + $project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere( + 'name = %s', + $request->getValue('arcanistProject')); + if (!$project || !$project->getRepositoryID()) { + return array(); + } + + $branch_name = $request->getValue('branch'); + if ($branch_name == '') { + $repository = id(new PhabricatorRepository()) + ->load($project->getRepositoryID()); + $branch_name = $repository->getDefaultArcanistBranch(); + } + + $branch = id(new PhabricatorRepositoryBranch())->loadOneWhere( + 'repositoryID = %d AND name = %s', + $project->getRepositoryID(), + $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; + } + +}