From 168bdaa87243a4f91a48c93a4194ddb5adb8fdd1 Mon Sep 17 00:00:00 2001 From: vrana Date: Thu, 8 Nov 2012 11:11:44 -0800 Subject: [PATCH] Display lint overview in Diffusion Summary: I will add links from /diffusion/ARC/lint/ in future diff. Test Plan: /diffusion/ - clicked on lint messages link. /diffusion/ARC/ - clicked on lint messages link. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3926 --- src/__phutil_library_map__.php | 2 + .../PhabricatorApplicationDiffusion.php | 1 + .../controller/DiffusionController.php | 10 +- .../controller/DiffusionHomeController.php | 15 ++- .../controller/DiffusionLintController.php | 93 +++++++++++++++++++ .../diffusion/request/DiffusionRequest.php | 2 + .../view/DiffusionBrowseTableView.php | 8 +- 7 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 src/applications/diffusion/controller/DiffusionLintController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ba43310a68..898a246470 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -360,6 +360,7 @@ phutil_register_library_map(array( 'DiffusionInlineCommentPreviewController' => 'applications/diffusion/controller/DiffusionInlineCommentPreviewController.php', 'DiffusionLastModifiedController' => 'applications/diffusion/controller/DiffusionLastModifiedController.php', 'DiffusionLastModifiedQuery' => 'applications/diffusion/query/lastmodified/DiffusionLastModifiedQuery.php', + 'DiffusionLintController' => 'applications/diffusion/controller/DiffusionLintController.php', 'DiffusionMercurialBranchQuery' => 'applications/diffusion/query/branch/DiffusionMercurialBranchQuery.php', 'DiffusionMercurialBrowseQuery' => 'applications/diffusion/query/browse/DiffusionMercurialBrowseQuery.php', 'DiffusionMercurialCommitParentsQuery' => 'applications/diffusion/query/parents/DiffusionMercurialCommitParentsQuery.php', @@ -1599,6 +1600,7 @@ phutil_register_library_map(array( 'DiffusionInlineCommentPreviewController' => 'PhabricatorInlineCommentPreviewController', 'DiffusionLastModifiedController' => 'DiffusionController', 'DiffusionLastModifiedQuery' => 'DiffusionQuery', + 'DiffusionLintController' => 'DiffusionController', 'DiffusionMercurialBranchQuery' => 'DiffusionBranchQuery', 'DiffusionMercurialBrowseQuery' => 'DiffusionBrowseQuery', 'DiffusionMercurialCommitParentsQuery' => 'DiffusionCommitParentsQuery', diff --git a/src/applications/diffusion/application/PhabricatorApplicationDiffusion.php b/src/applications/diffusion/application/PhabricatorApplicationDiffusion.php index 44a6f2749e..f02f6026d0 100644 --- a/src/applications/diffusion/application/PhabricatorApplicationDiffusion.php +++ b/src/applications/diffusion/application/PhabricatorApplicationDiffusion.php @@ -41,6 +41,7 @@ final class PhabricatorApplicationDiffusion extends PhabricatorApplication { 'diff/' => 'DiffusionDiffController', 'tags/(?P.*)' => 'DiffusionTagListController', 'branches/(?P.*)' => 'DiffusionBranchTableController', + 'lint/(?P.*)' => 'DiffusionLintController', 'commit/(?P[a-z0-9]+)/branches/' => 'DiffusionCommitBranchesController', diff --git a/src/applications/diffusion/controller/DiffusionController.php b/src/applications/diffusion/controller/DiffusionController.php index a29568d0e6..243e986bd4 100644 --- a/src/applications/diffusion/controller/DiffusionController.php +++ b/src/applications/diffusion/controller/DiffusionController.php @@ -53,6 +53,11 @@ abstract class DiffusionController extends PhabricatorController { } $drequest = $this->getDiffusionRequest(); + $branch = $drequest->loadBranch(); + + if ($branch && $branch->getLintCommit()) { + $navs['lint'] = 'Lint View'; + } foreach ($navs as $action => $name) { $href = $drequest->generateURI( @@ -243,6 +248,9 @@ abstract class DiffusionController extends PhabricatorController { case 'browse': $view_name = 'Browse'; break; + case 'lint': + $view_name = 'Lint'; + break; case 'change': $view_name = 'Change'; $crumb_list[] = phutil_escape_html($path).' ('.$commit_link.')'; @@ -306,7 +314,7 @@ abstract class DiffusionController extends PhabricatorController { ), 'Jump to HEAD'); $last_crumb .= " @ {$commit_link} ({$jump_link})"; - } else { + } else if ($spec['view'] != 'lint') { $last_crumb .= " @ HEAD"; } diff --git a/src/applications/diffusion/controller/DiffusionHomeController.php b/src/applications/diffusion/controller/DiffusionHomeController.php index a37c58a3ca..e3b1b6d520 100644 --- a/src/applications/diffusion/controller/DiffusionHomeController.php +++ b/src/applications/diffusion/controller/DiffusionHomeController.php @@ -98,11 +98,20 @@ final class DiffusionHomeController extends DiffusionController { number_format($size)); } + $lint_count = ''; $lint_branches = ipull(idx($lint_messages, $id, array()), 'n', 'name'); $branch = $repository->getDefaultArcanistBranch(); - if (isset($lint_branches[$branch])) { $show_lint = true; + $lint_count = phutil_render_tag( + 'a', + array( + 'href' => DiffusionRequest::generateDiffusionURI(array( + 'callsign' => $repository->getCallsign(), + 'action' => 'lint', + )), + ), + number_format($lint_branches[$branch])); } $date = '-'; @@ -123,9 +132,7 @@ final class DiffusionHomeController extends DiffusionController { PhabricatorRepositoryType::getNameForRepositoryType( $repository->getVersionControlSystem()), $size, - (isset($lint_branches[$branch]) - ? $lint_branches[$branch] - : ''), + $lint_count, $commit ? DiffusionView::linkCommit( $repository, diff --git a/src/applications/diffusion/controller/DiffusionLintController.php b/src/applications/diffusion/controller/DiffusionLintController.php new file mode 100644 index 0000000000..587b6b342d --- /dev/null +++ b/src/applications/diffusion/controller/DiffusionLintController.php @@ -0,0 +1,93 @@ +loadLintCodes(); + $codes = array_reverse(isort($codes, 'n')); + + $rows = array(); + foreach ($codes as $code) { + $rows[] = array( + $code['n'], + $code['files'], + phutil_escape_html(ArcanistLintSeverity::getStringForSeverity( + $code['maxSeverity'])), + phutil_escape_html($code['code']), + phutil_escape_html($code['maxName']), + phutil_escape_html($code['maxDescription']), + ); + } + + $table = id(new AphrontTableView($rows)) + ->setHeaders(array( + 'Problems', + 'Files', + 'Severity', + 'Code', + 'Name', + 'Example', + )); + + $content = array(); + + $content[] = $this->buildCrumbs( + array( + 'branch' => true, + 'path' => true, + 'view' => 'lint', + )); + + $content[] = id(new AphrontPanelView()) + ->setHeader(array_sum(ipull($codes, 'n')).' Lint Messages') + ->appendChild($table); + + $nav = $this->buildSideNav('lint', false); + $nav->appendChild($content); + + return $this->buildStandardPageResponse( + $nav, + array('title' => array( + 'Lint', + $this->getDiffusionRequest()->getRepository()->getCallsign(), + ))); + } + + private function loadLintCodes() { + $drequest = $this->getDiffusionRequest(); + $branch = $drequest->loadBranch(); + if (!$branch) { + return array(); + } + + $conn = $branch->establishConnection('r'); + + $where = ''; + if ($drequest->getPath() != '') { + $is_dir = (substr($drequest->getPath(), -1) == '/'); + $where = qsprintf( + $conn, + 'AND path '.($is_dir ? 'LIKE %>' : '= %s'), + '/'.$drequest->getPath()); + } + + return queryfx_all( + $conn, + 'SELECT + code, + MAX(severity) AS maxSeverity, + MAX(name) AS maxName, + MAX(description) AS maxDescription, + COUNT(DISTINCT path) AS files, + COUNT(*) AS n + FROM %T + WHERE branchID = %d + %Q + GROUP BY code', + PhabricatorRepository::TABLE_LINTMESSAGE, + $branch->getID(), + $where); + } + +} diff --git a/src/applications/diffusion/request/DiffusionRequest.php b/src/applications/diffusion/request/DiffusionRequest.php index f4f28ae44a..9efd98b07d 100644 --- a/src/applications/diffusion/request/DiffusionRequest.php +++ b/src/applications/diffusion/request/DiffusionRequest.php @@ -377,6 +377,7 @@ abstract class DiffusionRequest { case 'lastmodified': case 'tags': case 'branches': + case 'lint': $req_callsign = true; break; case 'branch': @@ -411,6 +412,7 @@ abstract class DiffusionRequest { case 'lastmodified': case 'tags': case 'branches': + case 'lint': $uri = "/diffusion/{$callsign}{$action}/{$path}{$commit}{$line}"; break; case 'branch': diff --git a/src/applications/diffusion/view/DiffusionBrowseTableView.php b/src/applications/diffusion/view/DiffusionBrowseTableView.php index 56eadba0be..de846f2478 100644 --- a/src/applications/diffusion/view/DiffusionBrowseTableView.php +++ b/src/applications/diffusion/view/DiffusionBrowseTableView.php @@ -81,8 +81,14 @@ final class DiffusionBrowseTableView extends DiffusionView { $lint = self::loadLintMessagesCount($drequest); if ($lint !== null) { - $return['lint'] = (string)$lint; + $return['lint'] = phutil_render_tag( + 'a', + array( + 'href' => $drequest->generateURI(array('action' => 'lint')), + ), + number_format($lint)); } + return $return; }