1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-23 02:38:48 +02:00
phorge-phorge/src/applications/diffusion/controller/DiffusionLintDetailsController.php
vrana 4f65d4f344 Display list of lint problems in Diffusion
Test Plan:
/diffusion/ARC/lint/master/, saw links.
/diffusion/ARC/lint/master/?lint=SPELL0, saw two links.
/diffusion/ARC/lint/master/src/lint/linter/ArcanistFilenameLinter.php?lint=SPELL0, saw link.
Clicked on everything.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2038

Differential Revision: https://secure.phabricator.com/D3931
2012-11-09 11:09:03 -08:00

131 lines
3.2 KiB
PHP

<?php
// Copyright 2004-present Facebook. All Rights Reserved.
final class DiffusionLintDetailsController extends DiffusionController {
public function processRequest() {
$limit = 500;
$offset = $this->getRequest()->getInt('offset', 0);
$drequest = $this->getDiffusionRequest();
$messages = $this->loadLintMessages($limit, $offset);
$is_dir = (substr('/'.$drequest->getPath(), -1) == '/');
$rows = array();
foreach ($messages as $message) {
$path = hsprintf(
'<a href="%s">%s</a>',
$drequest->generateURI(array(
'action' => 'lint',
'path' => $message['path'],
)),
substr($message['path'], strlen($drequest->getPath()) + 1));
$line = hsprintf(
'<a href="%s">%s</a>',
$drequest->generateURI(array(
'action' => 'browse',
'path' => $message['path'],
'line' => $message['line'],
)),
$message['line']);
$rows[] = array(
$path,
$line,
phutil_escape_html(ArcanistLintSeverity::getStringForSeverity(
$message['severity'])),
phutil_escape_html($message['code']),
phutil_escape_html($message['name']),
phutil_escape_html($message['description']),
);
}
$table = id(new AphrontTableView($rows))
->setHeaders(array(
'Path',
'Line',
'Severity',
'Code',
'Name',
'Example',
))
->setColumnClasses(array(
'',
'n',
'',
'pri',
'',
'',
))
->setColumnVisibility(array(
$is_dir,
));
$content = array();
$content[] = $this->buildCrumbs(
array(
'branch' => true,
'path' => true,
'view' => 'lint',
));
$pager = id(new AphrontPagerView())
->setPageSize($limit)
->setOffset($offset)
->setHasMorePages(count($messages) >= $limit)
->setURI($this->getRequest()->getRequestURI(), 'offset');
$content[] = id(new AphrontPanelView())
->setHeader(pht('%d Lint Message(s)', count($messages)))
->appendChild($table)
->appendChild($pager);
$nav = $this->buildSideNav('lint', false);
$nav->appendChild($content);
return $this->buildStandardPageResponse(
$nav,
array('title' => array(
'Lint',
$drequest->getRepository()->getCallsign(),
)));
}
private function loadLintMessages($limit, $offset) {
$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 *
FROM %T
WHERE branchID = %d
AND code = %s
%Q
LIMIT %d OFFSET %d',
// 'ORDER BY path, code, line' is disabled for performance reasons.
PhabricatorRepository::TABLE_LINTMESSAGE,
$branch->getID(),
$drequest->getLint(),
$where,
$limit,
$offset);
}
}