2012-11-08 20:11:44 +01:00
|
|
|
<?php
|
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
final class DiffusionLintController extends DiffusionController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
2012-11-09 00:14:44 +01:00
|
|
|
$drequest = $this->getDiffusionRequest();
|
|
|
|
|
2012-11-10 02:45:19 +01:00
|
|
|
if ($this->getRequest()->getStr('lint') !== null) {
|
2012-11-09 01:13:21 +01:00
|
|
|
$controller = new DiffusionLintDetailsController($this->getRequest());
|
|
|
|
$controller->setDiffusionRequest($drequest);
|
|
|
|
return $this->delegateToController($controller);
|
|
|
|
}
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
$codes = $this->loadLintCodes();
|
|
|
|
$codes = array_reverse(isort($codes, 'n'));
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($codes as $code) {
|
|
|
|
$rows[] = array(
|
2012-11-09 01:13:21 +01:00
|
|
|
hsprintf(
|
|
|
|
'<a href="%s">%s</a>',
|
|
|
|
$drequest->generateURI(array(
|
|
|
|
'action' => 'lint',
|
|
|
|
'lint' => $code['code'],
|
|
|
|
)),
|
|
|
|
$code['n']),
|
2012-11-09 00:14:44 +01:00
|
|
|
hsprintf(
|
|
|
|
'<a href="%s">%s</a>',
|
|
|
|
$drequest->generateURI(array(
|
|
|
|
'action' => 'browse',
|
|
|
|
'lint' => $code['code'],
|
|
|
|
)),
|
|
|
|
$code['files']),
|
2012-11-08 20:11:44 +01:00
|
|
|
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',
|
2012-11-09 00:14:44 +01:00
|
|
|
))
|
2012-11-10 02:45:19 +01:00
|
|
|
->setColumnClasses(array('n', 'n', '', 'pri', '', ''));
|
2012-11-08 20:11:44 +01:00
|
|
|
|
|
|
|
$content = array();
|
|
|
|
|
|
|
|
$content[] = $this->buildCrumbs(
|
|
|
|
array(
|
|
|
|
'branch' => true,
|
|
|
|
'path' => true,
|
|
|
|
'view' => 'lint',
|
|
|
|
));
|
|
|
|
|
2012-11-10 02:45:19 +01:00
|
|
|
$link = hsprintf(
|
|
|
|
'<a href="%s">%s</a>',
|
|
|
|
$drequest->generateURI(array(
|
|
|
|
'action' => 'lint',
|
|
|
|
'lint' => '',
|
|
|
|
)),
|
|
|
|
pht('Switch to List View'));
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
$content[] = id(new AphrontPanelView())
|
2012-11-09 01:13:21 +01:00
|
|
|
->setHeader(pht('%d Lint Message(s)', array_sum(ipull($codes, 'n'))))
|
2012-11-10 02:45:19 +01:00
|
|
|
->setCaption($link)
|
2012-11-08 20:11:44 +01:00
|
|
|
->appendChild($table);
|
|
|
|
|
|
|
|
$nav = $this->buildSideNav('lint', false);
|
|
|
|
$nav->appendChild($content);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
$nav,
|
|
|
|
array('title' => array(
|
|
|
|
'Lint',
|
2012-11-09 00:14:44 +01:00
|
|
|
$drequest->getRepository()->getCallsign(),
|
2012-11-08 20:11:44 +01:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|