mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-17 01:08:41 +01:00
Allow filtering by lint code in Diffusion
Test Plan: /diffusion/ARC/lint/master/src/, clicked on count link. /diffusion/ARC/browse/master/src/difference/?lint=XHP9, clicked on file name. /diffusion/ARC/browse/master/src/difference/ArcanistDiffUtils.php?lint=, verified that all messages are displayed. /diffusion/ARC/browse/master/src/difference/ArcanistDiffUtils.php?lint=XHP9. /diffusion/ARC/browse/master/src/difference/ArcanistDiffUtils.php?lint=TXT3, verified that 0 messages are displayed. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3929
This commit is contained in:
parent
168bdaa872
commit
726a4912bd
7 changed files with 87 additions and 20 deletions
|
@ -147,11 +147,22 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
||||||
$this->lintCommit = $branch->getLintCommit();
|
$this->lintCommit = $branch->getLintCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$conn = id(new PhabricatorRepository())->establishConnection('r');
|
||||||
|
|
||||||
|
$where = '';
|
||||||
|
if ($drequest->getLint()) {
|
||||||
|
$where = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'AND code = %s',
|
||||||
|
$drequest->getLint());
|
||||||
|
}
|
||||||
|
|
||||||
$this->lintMessages = queryfx_all(
|
$this->lintMessages = queryfx_all(
|
||||||
id(new PhabricatorRepository())->establishConnection('r'),
|
$conn,
|
||||||
'SELECT * FROM %T WHERE branchID = %d AND path = %s',
|
'SELECT * FROM %T WHERE branchID = %d %Q AND path = %s',
|
||||||
PhabricatorRepository::TABLE_LINTMESSAGE,
|
PhabricatorRepository::TABLE_LINTMESSAGE,
|
||||||
$branch->getID(),
|
$branch->getID(),
|
||||||
|
$where,
|
||||||
'/'.$drequest->getPath());
|
'/'.$drequest->getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,8 +342,8 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
||||||
|
|
||||||
|
|
||||||
$href = null;
|
$href = null;
|
||||||
if ($this->getRequest()->getBool('lint')) {
|
if ($this->getRequest()->getStr('lint') !== null) {
|
||||||
$lint_text = pht('Hide Lint Messages');
|
$lint_text = pht('Hide %d Lint Messages', count($this->lintMessages));
|
||||||
$href = $base_uri->alter('lint', null);
|
$href = $base_uri->alter('lint', null);
|
||||||
|
|
||||||
} else if ($this->lintCommit === null) {
|
} else if ($this->lintCommit === null) {
|
||||||
|
@ -345,14 +356,14 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
||||||
$href = $this->getDiffusionRequest()->generateURI(array(
|
$href = $this->getDiffusionRequest()->generateURI(array(
|
||||||
'action' => 'browse',
|
'action' => 'browse',
|
||||||
'commit' => $this->lintCommit,
|
'commit' => $this->lintCommit,
|
||||||
))->alter('lint', true);
|
))->alter('lint', '');
|
||||||
|
|
||||||
} else if (!$this->lintMessages) {
|
} else if (!$this->lintMessages) {
|
||||||
$lint_text = pht('0 Lint Messages');
|
$lint_text = pht('0 Lint Messages');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$lint_text = pht('Show %d Lint Message(s)', count($this->lintMessages));
|
$lint_text = pht('Show %d Lint Message(s)', count($this->lintMessages));
|
||||||
$href = $base_uri->alter('lint', true);
|
$href = $base_uri->alter('lint', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$lint_button = $this->createViewAction(
|
$lint_button = $this->createViewAction(
|
||||||
|
@ -556,7 +567,7 @@ final class DiffusionBrowseFileController extends DiffusionController {
|
||||||
|
|
||||||
$engine = null;
|
$engine = null;
|
||||||
$inlines = array();
|
$inlines = array();
|
||||||
if ($this->getRequest()->getBool('lint') && $this->lintMessages) {
|
if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) {
|
||||||
$engine = new PhabricatorMarkupEngine();
|
$engine = new PhabricatorMarkupEngine();
|
||||||
$engine->setViewer($user);
|
$engine->setViewer($user);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,9 @@ abstract class DiffusionController extends PhabricatorController {
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
if (isset($data['callsign'])) {
|
if (isset($data['callsign'])) {
|
||||||
$drequest = DiffusionRequest::newFromAphrontRequestDictionary($data);
|
$drequest = DiffusionRequest::newFromAphrontRequestDictionary(
|
||||||
|
$data,
|
||||||
|
$this->getRequest());
|
||||||
$this->diffusionRequest = $drequest;
|
$this->diffusionRequest = $drequest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,9 @@ final class DiffusionDiffController extends DiffusionController {
|
||||||
$data = $data + array(
|
$data = $data + array(
|
||||||
'dblob' => $this->getRequest()->getStr('ref'),
|
'dblob' => $this->getRequest()->getStr('ref'),
|
||||||
);
|
);
|
||||||
$drequest = DiffusionRequest::newFromAphrontRequestDictionary($data);
|
$drequest = DiffusionRequest::newFromAphrontRequestDictionary(
|
||||||
|
$data,
|
||||||
|
$this->getRequest());
|
||||||
|
|
||||||
$this->diffusionRequest = $drequest;
|
$this->diffusionRequest = $drequest;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
final class DiffusionLintController extends DiffusionController {
|
final class DiffusionLintController extends DiffusionController {
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
|
$drequest = $this->getDiffusionRequest();
|
||||||
|
|
||||||
$codes = $this->loadLintCodes();
|
$codes = $this->loadLintCodes();
|
||||||
$codes = array_reverse(isort($codes, 'n'));
|
$codes = array_reverse(isort($codes, 'n'));
|
||||||
|
|
||||||
|
@ -11,7 +13,13 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
foreach ($codes as $code) {
|
foreach ($codes as $code) {
|
||||||
$rows[] = array(
|
$rows[] = array(
|
||||||
$code['n'],
|
$code['n'],
|
||||||
$code['files'],
|
hsprintf(
|
||||||
|
'<a href="%s">%s</a>',
|
||||||
|
$drequest->generateURI(array(
|
||||||
|
'action' => 'browse',
|
||||||
|
'lint' => $code['code'],
|
||||||
|
)),
|
||||||
|
$code['files']),
|
||||||
phutil_escape_html(ArcanistLintSeverity::getStringForSeverity(
|
phutil_escape_html(ArcanistLintSeverity::getStringForSeverity(
|
||||||
$code['maxSeverity'])),
|
$code['maxSeverity'])),
|
||||||
phutil_escape_html($code['code']),
|
phutil_escape_html($code['code']),
|
||||||
|
@ -28,6 +36,14 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
'Code',
|
'Code',
|
||||||
'Name',
|
'Name',
|
||||||
'Example',
|
'Example',
|
||||||
|
))
|
||||||
|
->setColumnClasses(array(
|
||||||
|
'n',
|
||||||
|
'n',
|
||||||
|
'',
|
||||||
|
'pri',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
));
|
));
|
||||||
|
|
||||||
$content = array();
|
$content = array();
|
||||||
|
@ -50,7 +66,7 @@ final class DiffusionLintController extends DiffusionController {
|
||||||
$nav,
|
$nav,
|
||||||
array('title' => array(
|
array('title' => array(
|
||||||
'Lint',
|
'Lint',
|
||||||
$this->getDiffusionRequest()->getRepository()->getCallsign(),
|
$drequest->getRepository()->getCallsign(),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ abstract class DiffusionRequest {
|
||||||
protected $branch;
|
protected $branch;
|
||||||
protected $commitType = 'commit';
|
protected $commitType = 'commit';
|
||||||
protected $tagContent;
|
protected $tagContent;
|
||||||
|
protected $lint;
|
||||||
|
|
||||||
protected $repository;
|
protected $repository;
|
||||||
protected $repositoryCommit;
|
protected $repositoryCommit;
|
||||||
|
@ -80,7 +81,10 @@ abstract class DiffusionRequest {
|
||||||
* @return DiffusionRequest New request object.
|
* @return DiffusionRequest New request object.
|
||||||
* @task new
|
* @task new
|
||||||
*/
|
*/
|
||||||
final public static function newFromAphrontRequestDictionary(array $data) {
|
final public static function newFromAphrontRequestDictionary(
|
||||||
|
array $data,
|
||||||
|
AphrontRequest $request) {
|
||||||
|
|
||||||
$callsign = phutil_unescape_uri_path_component(idx($data, 'callsign'));
|
$callsign = phutil_unescape_uri_path_component(idx($data, 'callsign'));
|
||||||
$object = self::newFromCallsign($callsign);
|
$object = self::newFromCallsign($callsign);
|
||||||
|
|
||||||
|
@ -88,6 +92,7 @@ abstract class DiffusionRequest {
|
||||||
$parsed = self::parseRequestBlob(idx($data, 'dblob'), $use_branches);
|
$parsed = self::parseRequestBlob(idx($data, 'dblob'), $use_branches);
|
||||||
|
|
||||||
$object->initializeFromDictionary($parsed);
|
$object->initializeFromDictionary($parsed);
|
||||||
|
$object->lint = $request->getStr('lint');
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,6 +208,10 @@ abstract class DiffusionRequest {
|
||||||
return $this->branch;
|
return $this->branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLint() {
|
||||||
|
return $this->lint;
|
||||||
|
}
|
||||||
|
|
||||||
protected function getArcanistBranch() {
|
protected function getArcanistBranch() {
|
||||||
return $this->getBranch();
|
return $this->getBranch();
|
||||||
}
|
}
|
||||||
|
@ -303,6 +312,7 @@ abstract class DiffusionRequest {
|
||||||
'path' => $this->getPath(),
|
'path' => $this->getPath(),
|
||||||
'branch' => $this->getBranch(),
|
'branch' => $this->getBranch(),
|
||||||
'commit' => $default_commit,
|
'commit' => $default_commit,
|
||||||
|
'lint' => $this->getLint(),
|
||||||
);
|
);
|
||||||
foreach ($defaults as $key => $val) {
|
foreach ($defaults as $key => $val) {
|
||||||
if (!isset($params[$key])) { // Overwrite NULL.
|
if (!isset($params[$key])) { // Overwrite NULL.
|
||||||
|
@ -324,6 +334,7 @@ abstract class DiffusionRequest {
|
||||||
* - `path` Optional, path to file.
|
* - `path` Optional, path to file.
|
||||||
* - `commit` Optional, commit identifier.
|
* - `commit` Optional, commit identifier.
|
||||||
* - `line` Optional, line range.
|
* - `line` Optional, line range.
|
||||||
|
* - `lint` Optional, lint code.
|
||||||
* - `params` Optional, query parameters.
|
* - `params` Optional, query parameters.
|
||||||
*
|
*
|
||||||
* The function generates the specified URI and returns it.
|
* The function generates the specified URI and returns it.
|
||||||
|
@ -442,6 +453,13 @@ abstract class DiffusionRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = new PhutilURI($uri);
|
$uri = new PhutilURI($uri);
|
||||||
|
|
||||||
|
if (isset($params['lint'])) {
|
||||||
|
$params['params'] = idx($params, 'params', array()) + array(
|
||||||
|
'lint' => $params['lint'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (idx($params, 'params')) {
|
if (idx($params, 'params')) {
|
||||||
$uri->setQueryParams($params['params']);
|
$uri->setQueryParams($params['params']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,11 +81,12 @@ final class DiffusionBrowseTableView extends DiffusionView {
|
||||||
|
|
||||||
$lint = self::loadLintMessagesCount($drequest);
|
$lint = self::loadLintMessagesCount($drequest);
|
||||||
if ($lint !== null) {
|
if ($lint !== null) {
|
||||||
$return['lint'] = phutil_render_tag(
|
$return['lint'] = hsprintf(
|
||||||
'a',
|
'<a href="%s">%s</a>',
|
||||||
array(
|
$drequest->generateURI(array(
|
||||||
'href' => $drequest->generateURI(array('action' => 'lint')),
|
'action' => 'lint',
|
||||||
),
|
'lint' => '',
|
||||||
|
)),
|
||||||
number_format($lint));
|
number_format($lint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +99,23 @@ final class DiffusionBrowseTableView extends DiffusionView {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$conn = $drequest->getRepository()->establishConnection('r');
|
||||||
|
|
||||||
|
$where = '';
|
||||||
|
if ($drequest->getLint()) {
|
||||||
|
$where = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'AND code = %s',
|
||||||
|
$drequest->getLint());
|
||||||
|
}
|
||||||
|
|
||||||
$like = (substr($drequest->getPath(), -1) == '/' ? 'LIKE %>' : '= %s');
|
$like = (substr($drequest->getPath(), -1) == '/' ? 'LIKE %>' : '= %s');
|
||||||
return head(queryfx_one(
|
return head(queryfx_one(
|
||||||
$drequest->getRepository()->establishConnection('r'),
|
$conn,
|
||||||
'SELECT COUNT(*) FROM %T WHERE branchID = %d AND path '.$like,
|
'SELECT COUNT(*) FROM %T WHERE branchID = %d %Q AND path '.$like,
|
||||||
PhabricatorRepository::TABLE_LINTMESSAGE,
|
PhabricatorRepository::TABLE_LINTMESSAGE,
|
||||||
$branch->getID(),
|
$branch->getID(),
|
||||||
|
$where,
|
||||||
'/'.$drequest->getPath()));
|
'/'.$drequest->getPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +238,7 @@ final class DiffusionBrowseTableView extends DiffusionView {
|
||||||
|
|
||||||
$branch = $this->getDiffusionRequest()->loadBranch();
|
$branch = $this->getDiffusionRequest()->loadBranch();
|
||||||
$show_lint = ($branch && $branch->getLintCommit());
|
$show_lint = ($branch && $branch->getLintCommit());
|
||||||
|
$lint = $request->getLint();
|
||||||
|
|
||||||
$view = new AphrontTableView($rows);
|
$view = new AphrontTableView($rows);
|
||||||
$view->setHeaders(
|
$view->setHeaders(
|
||||||
|
@ -233,7 +246,7 @@ final class DiffusionBrowseTableView extends DiffusionView {
|
||||||
'History',
|
'History',
|
||||||
'Edit',
|
'Edit',
|
||||||
'Path',
|
'Path',
|
||||||
'Lint',
|
($lint ? phutil_escape_html($lint) : 'Lint'),
|
||||||
'Modified',
|
'Modified',
|
||||||
'Date',
|
'Date',
|
||||||
'Time',
|
'Time',
|
||||||
|
|
|
@ -155,6 +155,11 @@ abstract class PhabricatorBaseEnglishTranslation
|
||||||
'Show %d Lint Messages',
|
'Show %d Lint Messages',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'Hide %d Lint Message(s)' => array(
|
||||||
|
'Hide %d Lint Message',
|
||||||
|
'Hide %d Lint Messages',
|
||||||
|
),
|
||||||
|
|
||||||
'Switch for %d Lint Message(s)' => array(
|
'Switch for %d Lint Message(s)' => array(
|
||||||
'Switch for %d Lint Message',
|
'Switch for %d Lint Message',
|
||||||
'Switch for %d Lint Messages',
|
'Switch for %d Lint Messages',
|
||||||
|
|
Loading…
Add table
Reference in a new issue