2012-11-08 20:11:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionLintController extends DiffusionController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
2012-12-03 23:13:38 +01:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $this->getRequest()->getUser();
|
2012-12-03 22:12:19 +01:00
|
|
|
$drequest = $this->diffusionRequest;
|
2012-11-09 00:14:44 +01:00
|
|
|
|
2012-12-03 23:13:38 +01:00
|
|
|
if ($request->getStr('lint') !== null) {
|
|
|
|
$controller = new DiffusionLintDetailsController($request);
|
2012-11-09 01:13:21 +01:00
|
|
|
$controller->setDiffusionRequest($drequest);
|
|
|
|
return $this->delegateToController($controller);
|
|
|
|
}
|
|
|
|
|
2012-12-03 23:13:38 +01:00
|
|
|
$owners = array();
|
2012-12-03 22:12:19 +01:00
|
|
|
if (!$drequest) {
|
2012-12-03 23:13:38 +01:00
|
|
|
if (!$request->getArr('owner')) {
|
|
|
|
$owners[$user->getPHID()] = $user->getFullName();
|
|
|
|
} else {
|
|
|
|
$phids = $request->getArr('owner');
|
|
|
|
$phid = reset($phids);
|
|
|
|
$handles = $this->loadViewerHandles(array($phid));
|
|
|
|
$owners[$phid] = $handles[$phid]->getFullName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$codes = $this->loadLintCodes(array_keys($owners));
|
|
|
|
|
|
|
|
if ($codes && !$drequest) {
|
2012-12-03 22:12:19 +01:00
|
|
|
$branches = id(new PhabricatorRepositoryBranch())->loadAllWhere(
|
|
|
|
'id IN (%Ld)',
|
|
|
|
array_unique(ipull($codes, 'branchID')));
|
|
|
|
|
|
|
|
$repositories = id(new PhabricatorRepository())->loadAllWhere(
|
|
|
|
'id IN (%Ld)',
|
|
|
|
array_unique(mpull($branches, 'getRepositoryID')));
|
|
|
|
|
|
|
|
$drequests = array();
|
|
|
|
foreach ($branches as $id => $branch) {
|
|
|
|
$drequests[$id] = DiffusionRequest::newFromDictionary(array(
|
|
|
|
'repository' => $repositories[$branch->getRepositoryID()],
|
|
|
|
'branch' => $branch->getName(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
$rows = array();
|
|
|
|
foreach ($codes as $code) {
|
2012-12-03 22:12:19 +01:00
|
|
|
if (!$this->diffusionRequest) {
|
|
|
|
$drequest = $drequests[$code['branchID']];
|
|
|
|
}
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
$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-12-03 22:12:19 +01:00
|
|
|
hsprintf(
|
|
|
|
'<a href="%s">%s</a>',
|
|
|
|
$drequest->generateURI(array('action' => 'lint')),
|
|
|
|
$drequest->getCallsign()),
|
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',
|
2012-12-03 22:12:19 +01:00
|
|
|
'Repository',
|
2012-11-08 20:11:44 +01:00
|
|
|
'Severity',
|
|
|
|
'Code',
|
|
|
|
'Name',
|
|
|
|
'Example',
|
2012-11-09 00:14:44 +01:00
|
|
|
))
|
2012-12-03 22:12:19 +01:00
|
|
|
->setColumnVisibility(array(true, true, !$this->diffusionRequest))
|
|
|
|
->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-12-03 23:13:38 +01:00
|
|
|
|
2012-12-03 22:12:19 +01:00
|
|
|
$link = null;
|
|
|
|
if ($this->diffusionRequest) {
|
|
|
|
$link = hsprintf(
|
|
|
|
'<a href="%s">%s</a>',
|
|
|
|
$drequest->generateURI(array(
|
|
|
|
'action' => 'lint',
|
|
|
|
'lint' => '',
|
|
|
|
)),
|
|
|
|
pht('Switch to List View'));
|
2012-12-03 23:13:38 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->setMethod('GET')
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
|
|
|
->setLimit(1)
|
|
|
|
->setName('owner')
|
|
|
|
->setLabel('Owner')
|
|
|
|
->setValue($owners))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->setValue('Filter'));
|
|
|
|
$content[] = id(new AphrontListFilterView())->appendChild($form);
|
2012-12-03 22:12:19 +01:00
|
|
|
}
|
2012-11-10 02:45:19 +01:00
|
|
|
|
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);
|
|
|
|
|
2012-12-03 22:12:19 +01:00
|
|
|
$title = array('Lint');
|
|
|
|
if ($this->diffusionRequest) {
|
|
|
|
$title[] = $drequest->getCallsign();
|
|
|
|
$content = $this->buildSideNav('lint', false)->appendChild($content);
|
|
|
|
}
|
2012-11-08 20:11:44 +01:00
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
2012-12-03 22:12:19 +01:00
|
|
|
$content,
|
|
|
|
array('title' => $title));
|
2012-11-08 20:11:44 +01:00
|
|
|
}
|
|
|
|
|
2012-12-03 23:13:38 +01:00
|
|
|
private function loadLintCodes(array $owner_phids) {
|
2012-12-03 22:12:19 +01:00
|
|
|
$drequest = $this->diffusionRequest;
|
|
|
|
$conn = id(new PhabricatorRepository())->establishConnection('r');
|
|
|
|
$where = array('1 = 1');
|
|
|
|
|
|
|
|
if ($drequest) {
|
|
|
|
$branch = $drequest->loadBranch();
|
|
|
|
if (!$branch) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$where[] = qsprintf($conn, 'branchID = %d', $branch->getID());
|
|
|
|
|
|
|
|
if ($drequest->getPath() != '') {
|
|
|
|
$is_dir = (substr($drequest->getPath(), -1) == '/');
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'path '.($is_dir ? 'LIKE %>' : '= %s'),
|
|
|
|
'/'.$drequest->getPath());
|
|
|
|
}
|
2012-11-08 20:11:44 +01:00
|
|
|
}
|
|
|
|
|
2012-12-03 23:13:38 +01:00
|
|
|
if ($owner_phids) {
|
|
|
|
$packages = id(new PhabricatorOwnersOwner())
|
|
|
|
->loadAllWhere('userPHID IN (%Ls)', $owner_phids);
|
|
|
|
if (!$packages) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths = id(new PhabricatorOwnersPath())
|
|
|
|
->loadAllWhere('packageID IN (%Ld)', array_keys($packages));
|
|
|
|
if (!$paths) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$repositories = id(new PhabricatorRepository())->loadAllWhere(
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
array_unique(mpull($paths, 'getRepositoryPHID')));
|
|
|
|
$repositories = mpull($repositories, 'getID', 'getPHID');
|
|
|
|
|
|
|
|
$branches = id(new PhabricatorRepositoryBranch())->loadAllWhere(
|
|
|
|
'repositoryID IN (%Ld)',
|
|
|
|
$repositories);
|
|
|
|
$branches = mgroup($branches, 'getRepositoryID');
|
|
|
|
|
|
|
|
$or = array();
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
$branch = idx($branches, $repositories[$path->getRepositoryPHID()]);
|
|
|
|
if ($branch) {
|
2012-12-07 02:23:56 +01:00
|
|
|
$condition = qsprintf(
|
2012-12-03 23:13:38 +01:00
|
|
|
$conn,
|
|
|
|
'(branchID IN (%Ld) AND path LIKE %>)',
|
|
|
|
array_keys($branch),
|
|
|
|
$path->getPath());
|
2012-12-07 02:23:56 +01:00
|
|
|
if ($path->getExcluded()) {
|
|
|
|
$where[] = 'NOT '.$condition;
|
|
|
|
} else {
|
|
|
|
$or[] = $condition;
|
|
|
|
}
|
2012-12-03 23:13:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$or) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
$where[] = '('.implode(' OR ', $or).')';
|
|
|
|
}
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
return queryfx_all(
|
|
|
|
$conn,
|
|
|
|
'SELECT
|
2012-12-03 22:12:19 +01:00
|
|
|
branchID,
|
2012-11-08 20:11:44 +01:00
|
|
|
code,
|
|
|
|
MAX(severity) AS maxSeverity,
|
|
|
|
MAX(name) AS maxName,
|
|
|
|
MAX(description) AS maxDescription,
|
|
|
|
COUNT(DISTINCT path) AS files,
|
|
|
|
COUNT(*) AS n
|
|
|
|
FROM %T
|
2012-12-03 22:12:19 +01:00
|
|
|
WHERE %Q
|
2012-12-03 23:13:38 +01:00
|
|
|
GROUP BY branchID, code
|
|
|
|
ORDER BY n DESC',
|
2012-11-08 20:11:44 +01:00
|
|
|
PhabricatorRepository::TABLE_LINTMESSAGE,
|
2012-12-03 22:12:19 +01:00
|
|
|
implode(' AND ', $where));
|
2012-11-08 20:11:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|