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);
|
upgrade diffusion to use modern header UI and fix a few quirks
Summary:
upgrades are CrumbsView, HeaderView, PropertyListView, and ActionListView. I had to modify CrumbsView stuff a bit to handle the "advanced" diffusion crumbs.
Quirks fixed include making file tree view show up in diffusion, the page not have extra space when the file tree is hidden, links no longer breaking once you visit files (since without the change the files always got "/" appended and thus 404'd), and a differential quirk where it read "next step:" and that colon is a no no,
Test Plan: played around in diffusion and differential
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin, chad
Maniphest Tasks: T2048, T2178
Differential Revision: https://secure.phabricator.com/D4169
2012-12-13 02:50:42 +01:00
|
|
|
$controller->setCurrentApplication($this->getCurrentApplication());
|
2012-11-09 01:13:21 +01:00
|
|
|
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()),
|
2013-02-13 23:50:15 +01:00
|
|
|
ArcanistLintSeverity::getStringForSeverity($code['maxSeverity']),
|
|
|
|
$code['code'],
|
|
|
|
$code['maxName'],
|
|
|
|
$code['maxDescription'],
|
2012-11-08 20:11:44 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
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');
|
upgrade diffusion to use modern header UI and fix a few quirks
Summary:
upgrades are CrumbsView, HeaderView, PropertyListView, and ActionListView. I had to modify CrumbsView stuff a bit to handle the "advanced" diffusion crumbs.
Quirks fixed include making file tree view show up in diffusion, the page not have extra space when the file tree is hidden, links no longer breaking once you visit files (since without the change the files always got "/" appended and thus 404'd), and a differential quirk where it read "next step:" and that colon is a no no,
Test Plan: played around in diffusion and differential
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin, chad
Maniphest Tasks: T2048, T2178
Differential Revision: https://secure.phabricator.com/D4169
2012-12-13 02:50:42 +01:00
|
|
|
$crumbs = $this->buildCrumbs(
|
|
|
|
array(
|
|
|
|
'branch' => true,
|
|
|
|
'path' => true,
|
|
|
|
'view' => 'lint',
|
|
|
|
));
|
2012-12-03 22:12:19 +01:00
|
|
|
if ($this->diffusionRequest) {
|
|
|
|
$title[] = $drequest->getCallsign();
|
upgrade diffusion to use modern header UI and fix a few quirks
Summary:
upgrades are CrumbsView, HeaderView, PropertyListView, and ActionListView. I had to modify CrumbsView stuff a bit to handle the "advanced" diffusion crumbs.
Quirks fixed include making file tree view show up in diffusion, the page not have extra space when the file tree is hidden, links no longer breaking once you visit files (since without the change the files always got "/" appended and thus 404'd), and a differential quirk where it read "next step:" and that colon is a no no,
Test Plan: played around in diffusion and differential
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin, chad
Maniphest Tasks: T2048, T2178
Differential Revision: https://secure.phabricator.com/D4169
2012-12-13 02:50:42 +01:00
|
|
|
$content = $this->buildSideNav('lint', false)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($content);
|
|
|
|
} else {
|
|
|
|
array_unshift($content, $crumbs);
|
2012-12-03 22:12:19 +01:00
|
|
|
}
|
2012-11-08 20:11:44 +01:00
|
|
|
|
upgrade diffusion to use modern header UI and fix a few quirks
Summary:
upgrades are CrumbsView, HeaderView, PropertyListView, and ActionListView. I had to modify CrumbsView stuff a bit to handle the "advanced" diffusion crumbs.
Quirks fixed include making file tree view show up in diffusion, the page not have extra space when the file tree is hidden, links no longer breaking once you visit files (since without the change the files always got "/" appended and thus 404'd), and a differential quirk where it read "next step:" and that colon is a no no,
Test Plan: played around in diffusion and differential
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, Korvin, chad
Maniphest Tasks: T2048, T2178
Differential Revision: https://secure.phabricator.com/D4169
2012-12-13 02:50:42 +01:00
|
|
|
return $this->buildApplicationPage(
|
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() != '') {
|
2013-02-04 00:04:15 +01:00
|
|
|
$path = '/'.$drequest->getPath();
|
|
|
|
$is_dir = (substr($path, -1) == '/');
|
|
|
|
$where[] = ($is_dir
|
|
|
|
? qsprintf($conn, 'path LIKE %>', $path)
|
|
|
|
: qsprintf($conn, 'path = %s', $path));
|
2012-12-03 22:12:19 +01:00
|
|
|
}
|
2012-11-08 20:11:44 +01:00
|
|
|
}
|
|
|
|
|
2012-12-03 23:13:38 +01:00
|
|
|
if ($owner_phids) {
|
2013-03-05 01:22:30 +01:00
|
|
|
$or = array();
|
|
|
|
$or[] = qsprintf($conn, 'authorPHID IN (%Ls)', $owner_phids);
|
|
|
|
|
|
|
|
$paths = array();
|
2012-12-03 23:13:38 +01:00
|
|
|
$packages = id(new PhabricatorOwnersOwner())
|
|
|
|
->loadAllWhere('userPHID IN (%Ls)', $owner_phids);
|
2013-03-05 01:22:30 +01:00
|
|
|
if ($packages) {
|
|
|
|
$paths = id(new PhabricatorOwnersPath())->loadAllWhere(
|
|
|
|
'packageID IN (%Ld)',
|
|
|
|
mpull($packages, 'getPackageID'));
|
2012-12-03 23:13:38 +01:00
|
|
|
}
|
|
|
|
|
2013-03-05 01:22:30 +01:00
|
|
|
if ($paths) {
|
|
|
|
$repositories = id(new PhabricatorRepository())->loadAllWhere(
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
array_unique(mpull($paths, 'getRepositoryPHID')));
|
|
|
|
$repositories = mpull($repositories, 'getID', 'getPHID');
|
2012-12-03 23:13:38 +01:00
|
|
|
|
2013-03-05 01:22:30 +01:00
|
|
|
$branches = id(new PhabricatorRepositoryBranch())->loadAllWhere(
|
|
|
|
'repositoryID IN (%Ld)',
|
|
|
|
$repositories);
|
|
|
|
$branches = mgroup($branches, 'getRepositoryID');
|
|
|
|
}
|
2012-12-03 23:13:38 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
|
|
|
}
|