2012-11-08 20:11:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DiffusionLintController extends DiffusionController {
|
|
|
|
|
2013-09-23 21:55:47 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
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) {
|
Decouple some aspects of request routing and construction
Summary:
Ref T5702. This is a forward-looking change which provides some very broad API improvements but does not implement them. In particular:
- Controllers no longer require `$request` to construct. This is mostly for T5702, directly, but simplifies things in general. Instead, we call `setRequest()` before using a controller. Only a small number of sites activate controllers, so this is less code overall, and more consistent with most constructors not having any parameters or effects.
- `$request` now offers `getURIData($key, ...)`. This is an alternate way of accessing `$data` which is currently only available on `willProcessRequest(array $data)`. Almost all controllers which implement this method do so in order to read one or two things out of the URI data. Instead, let them just read this data directly when processing the request.
- Introduce `handleRequest(AphrontRequest $request)` and deprecate (very softly) `processRequest()`. The majority of `processRequest()` calls begin `$request = $this->getRequest()`, which is avoided with the more practical signature.
- Provide `getViewer()` on `$request`, and a convenience `getViewer()` on `$controller`. This fixes `$viewer = $request->getUser();` into `$viewer = $request->getViewer();`, and converts the `$request + $viewer` two-liner into a single `$this->getViewer()`.
Test Plan:
- Browsed around in general.
- Hit special controllers (redirect, 404).
- Hit AuditList controller (uses new style).
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5702
Differential Revision: https://secure.phabricator.com/D10698
2014-10-17 14:01:40 +02:00
|
|
|
$controller = new DiffusionLintDetailsController();
|
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')) {
|
2013-10-07 21:51:24 +02:00
|
|
|
$owners = array($user->getPHID());
|
2012-12-03 23:13:38 +01:00
|
|
|
} else {
|
2013-10-07 21:51:24 +02:00
|
|
|
$owners = array(head($request->getArr('owner')));
|
2012-12-03 23:13:38 +01:00
|
|
|
}
|
2013-10-07 21:51:24 +02:00
|
|
|
$owner_handles = $this->loadViewerHandles($owners);
|
2012-12-03 23:13:38 +01:00
|
|
|
}
|
|
|
|
|
2013-10-07 21:51:24 +02:00
|
|
|
$codes = $this->loadLintCodes($owners);
|
2012-12-03 23:13:38 +01:00
|
|
|
|
|
|
|
if ($codes && !$drequest) {
|
2013-09-23 21:55:47 +02:00
|
|
|
// TODO: Build some real Query classes for this stuff.
|
|
|
|
|
2012-12-03 22:12:19 +01:00
|
|
|
$branches = id(new PhabricatorRepositoryBranch())->loadAllWhere(
|
|
|
|
'id IN (%Ld)',
|
|
|
|
array_unique(ipull($codes, 'branchID')));
|
|
|
|
|
2013-09-23 21:55:47 +02:00
|
|
|
$repositories = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(mpull($branches, 'getRepositoryID'))
|
|
|
|
->execute();
|
2012-12-03 22:12:19 +01:00
|
|
|
|
|
|
|
$drequests = array();
|
|
|
|
foreach ($branches as $id => $branch) {
|
2013-09-23 21:55:47 +02:00
|
|
|
if (empty($repositories[$branch->getRepositoryID()])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-12-03 22:12:19 +01:00
|
|
|
$drequests[$id] = DiffusionRequest::newFromDictionary(array(
|
2013-05-15 00:32:19 +02:00
|
|
|
'user' => $user,
|
2012-12-03 22:12:19 +01:00
|
|
|
'repository' => $repositories[$branch->getRepositoryID()],
|
|
|
|
'branch' => $branch->getName(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
$rows = array();
|
2013-09-23 21:55:47 +02:00
|
|
|
$total = 0;
|
2012-11-08 20:11:44 +01:00
|
|
|
foreach ($codes as $code) {
|
2012-12-03 22:12:19 +01:00
|
|
|
if (!$this->diffusionRequest) {
|
2013-09-23 21:55:47 +02:00
|
|
|
$drequest = idx($drequests, $code['branchID']);
|
2012-12-03 22:12:19 +01:00
|
|
|
}
|
|
|
|
|
2013-09-23 21:55:47 +02:00
|
|
|
if (!$drequest) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$total += $code['n'];
|
|
|
|
|
2013-11-11 18:23:23 +01:00
|
|
|
$href_lint = $drequest->generateURI(array(
|
|
|
|
'action' => 'lint',
|
|
|
|
'lint' => $code['code'],
|
|
|
|
));
|
|
|
|
$href_browse = $drequest->generateURI(array(
|
|
|
|
'action' => 'browse',
|
|
|
|
'lint' => $code['code'],
|
|
|
|
));
|
|
|
|
$href_repo = $drequest->generateURI(array('action' => 'lint'));
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
$rows[] = array(
|
2013-11-11 18:23:23 +01:00
|
|
|
phutil_tag('a', array('href' => $href_lint), $code['n']),
|
|
|
|
phutil_tag('a', array('href' => $href_browse), $code['files']),
|
|
|
|
phutil_tag('a', array('href' => $href_repo), $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(
|
2013-05-11 17:23:19 +02:00
|
|
|
pht('Problems'),
|
|
|
|
pht('Files'),
|
|
|
|
pht('Repository'),
|
|
|
|
pht('Severity'),
|
|
|
|
pht('Code'),
|
|
|
|
pht('Name'),
|
|
|
|
pht('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;
|
2013-09-23 21:55:47 +02:00
|
|
|
if (!$this->diffusionRequest) {
|
2012-12-03 23:13:38 +01:00
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($user)
|
|
|
|
->setMethod('GET')
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
2012-12-03 23:13:38 +01:00
|
|
|
->setLimit(1)
|
|
|
|
->setName('owner')
|
2013-05-11 17:23:19 +02:00
|
|
|
->setLabel(pht('Owner'))
|
2013-10-07 21:51:24 +02:00
|
|
|
->setValue($owner_handles))
|
2012-12-03 23:13:38 +01:00
|
|
|
->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())
|
2013-09-23 21:55:47 +02:00
|
|
|
->setNoBackground(true)
|
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',
|
|
|
|
));
|
2013-09-23 21:55:47 +02:00
|
|
|
|
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
|
|
|
} else {
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('All Lint'));
|
2013-09-23 21:55:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->diffusionRequest) {
|
|
|
|
$branch = $drequest->loadBranch();
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($this->renderPathLinks($drequest, 'lint'))
|
|
|
|
->setUser($user)
|
|
|
|
->setPolicyObject($drequest->getRepository());
|
|
|
|
$actions = $this->buildActionView($drequest);
|
|
|
|
$properties = $this->buildPropertyView(
|
|
|
|
$drequest,
|
|
|
|
$branch,
|
2013-10-11 16:53:56 +02:00
|
|
|
$total,
|
|
|
|
$actions);
|
2013-09-29 00:55:38 +02:00
|
|
|
|
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
2013-10-11 16:53:56 +02:00
|
|
|
->addPropertyList($properties);
|
2013-09-23 21:55:47 +02:00
|
|
|
} else {
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = null;
|
2012-12-03 22:12:19 +01:00
|
|
|
}
|
2012-11-08 20:11:44 +01:00
|
|
|
|
2013-09-23 21:55:47 +02: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(
|
2013-09-23 21:55:47 +02:00
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box,
|
2013-09-23 21:55:47 +02:00
|
|
|
$content,
|
|
|
|
),
|
2013-05-11 17:23:19 +02:00
|
|
|
array(
|
|
|
|
'title' => $title,
|
2013-09-23 21:55:47 +02:00
|
|
|
));
|
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) {
|
2013-09-26 01:54:48 +02:00
|
|
|
$repositories = id(new PhabricatorRepositoryQuery())
|
|
|
|
->setViewer($this->getRequest()->getUser())
|
|
|
|
->withPHIDs(mpull($paths, 'getRepositoryPHID'))
|
|
|
|
->execute();
|
2013-03-05 01:22:30 +01:00
|
|
|
$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) {
|
2013-09-26 01:54:48 +02:00
|
|
|
$branch = idx(
|
|
|
|
$branches,
|
|
|
|
idx(
|
|
|
|
$repositories,
|
|
|
|
$path->getRepositoryPHID()));
|
2012-12-03 23:13:38 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-09-23 21:55:47 +02:00
|
|
|
protected function buildActionView(DiffusionRequest $drequest) {
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$list_uri = $drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'lint',
|
|
|
|
'lint' => '',
|
|
|
|
));
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('View As List'))
|
|
|
|
->setHref($list_uri)
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-list'));
|
2013-09-23 21:55:47 +02:00
|
|
|
|
|
|
|
$history_uri = $drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'history',
|
|
|
|
));
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('View History'))
|
|
|
|
->setHref($history_uri)
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-clock-o'));
|
2013-09-23 21:55:47 +02:00
|
|
|
|
|
|
|
$browse_uri = $drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'browse',
|
|
|
|
));
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Browse Content'))
|
|
|
|
->setHref($browse_uri)
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-files-o'));
|
2013-09-23 21:55:47 +02:00
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function buildPropertyView(
|
|
|
|
DiffusionRequest $drequest,
|
|
|
|
PhabricatorRepositoryBranch $branch,
|
2013-10-11 16:53:56 +02:00
|
|
|
$total,
|
|
|
|
PhabricatorActionListView $actions) {
|
2013-09-23 21:55:47 +02:00
|
|
|
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$view = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer)
|
2013-11-18 17:05:27 +01:00
|
|
|
->setActionList($actions);
|
2013-09-23 21:55:47 +02:00
|
|
|
|
|
|
|
$callsign = $drequest->getRepository()->getCallsign();
|
|
|
|
$lint_commit = $branch->getLintCommit();
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Lint Commit'),
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $drequest->generateURI(
|
|
|
|
array(
|
|
|
|
'action' => 'commit',
|
|
|
|
'commit' => $lint_commit,
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
$drequest->getRepository()->formatCommitName($lint_commit)));
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Total Messages'),
|
|
|
|
pht('%s', new PhutilNumber($total)));
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-08 20:11:44 +01:00
|
|
|
}
|