mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-02 01:48:23 +01:00
In Diffusion browse views, show a README file if one exists
Summary: COMPLETELY ORIGINAL IDEA Test Plan: Browsed around Phabricator, got helpful readmes in some cases. Reviewers: davidreuss, btrahan Reviewed By: btrahan CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D2022
This commit is contained in:
parent
5ba6e241c4
commit
59b49e6429
5 changed files with 54 additions and 40 deletions
|
@ -253,7 +253,7 @@ abstract class DiffusionController extends PhabricatorController {
|
|||
array(
|
||||
'href' => $drequest->generateURI(
|
||||
array(
|
||||
'path' => null,
|
||||
'path' => '',
|
||||
) + $uri_params),
|
||||
),
|
||||
$view_name);
|
||||
|
|
|
@ -49,6 +49,8 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
|
||||
} else {
|
||||
|
||||
$readme = null;
|
||||
|
||||
$phids = array();
|
||||
foreach ($results as $result) {
|
||||
$data = $result->getLastCommitData();
|
||||
|
@ -57,11 +59,53 @@ final class DiffusionBrowseController extends DiffusionController {
|
|||
$phids[$data->getCommitDetail('authorPHID')] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$phids = array_keys($phids);
|
||||
|
||||
$path = $result->getPath();
|
||||
if (preg_match('/^readme(|\.txt|\.remarkup)$/i', $path)) {
|
||||
$readme = $result;
|
||||
}
|
||||
}
|
||||
|
||||
$phids = array_keys($phids);
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
||||
|
||||
if ($readme) {
|
||||
$readme_request = DiffusionRequest::newFromDictionary(
|
||||
array(
|
||||
'repository' => $drequest->getRepository(),
|
||||
'commit' => $drequest->getStableCommitName(),
|
||||
'path' => $readme->getFullPath(),
|
||||
));
|
||||
|
||||
$content_query = DiffusionFileContentQuery::newFromDiffusionRequest(
|
||||
$readme_request);
|
||||
$content_query->loadFileContent();
|
||||
$readme_content = $content_query->getRawData();
|
||||
|
||||
if (preg_match('/.txt$/', $readme->getPath())) {
|
||||
$readme_content = phutil_escape_html($readme_content);
|
||||
$readme_content = nl2br($readme_content);
|
||||
} else {
|
||||
// Markup extensionless files as remarkup so we get links and such.
|
||||
|
||||
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
|
||||
$readme_content = $engine->markupText($readme_content);
|
||||
|
||||
$readme_content = phutil_render_tag(
|
||||
'div',
|
||||
array(
|
||||
'class' => 'phabricator-remarkup',
|
||||
),
|
||||
$readme_content);
|
||||
}
|
||||
|
||||
$readme_panel = new AphrontPanelView();
|
||||
$readme_panel->setHeader('README');
|
||||
$readme_panel->appendChild($readme_content);
|
||||
|
||||
$content[] = $readme_panel;
|
||||
}
|
||||
|
||||
$browse_table = new DiffusionBrowseTableView();
|
||||
$browse_table->setDiffusionRequest($drequest);
|
||||
$browse_table->setHandles($handles);
|
||||
|
|
|
@ -9,11 +9,15 @@
|
|||
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/controller/file');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/browse/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/filecontent/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/request/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/browsetable');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/view/emptyresult');
|
||||
phutil_require_module('phabricator', 'applications/markup/engine');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
|
|
|
@ -16,41 +16,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
abstract class DiffusionFileContentQuery {
|
||||
abstract class DiffusionFileContentQuery extends DiffusionQuery {
|
||||
|
||||
private $request;
|
||||
private $needsBlame;
|
||||
private $fileContent;
|
||||
|
||||
final private function __construct() {
|
||||
// <private>
|
||||
}
|
||||
|
||||
final public static function newFromDiffusionRequest(
|
||||
DiffusionRequest $request) {
|
||||
|
||||
$repository = $request->getRepository();
|
||||
|
||||
switch ($repository->getVersionControlSystem()) {
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
|
||||
$class = 'DiffusionGitFileContentQuery';
|
||||
break;
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL:
|
||||
$class = 'DiffusionMercurialFileContentQuery';
|
||||
break;
|
||||
case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
|
||||
$class = 'DiffusionSvnFileContentQuery';
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unsupported VCS!");
|
||||
}
|
||||
|
||||
PhutilSymbolLoader::loadClass($class);
|
||||
$query = new $class();
|
||||
|
||||
$query->request = $request;
|
||||
|
||||
return $query;
|
||||
return parent::newQueryObject(__CLASS__, $request);
|
||||
}
|
||||
|
||||
public function getSupportsBlameOnBlame() {
|
||||
|
@ -63,16 +36,10 @@ abstract class DiffusionFileContentQuery {
|
|||
throw new Exception("Unsupported VCS!");
|
||||
}
|
||||
|
||||
final protected function getRequest() {
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
final public function loadFileContent() {
|
||||
$this->fileContent = $this->executeQuery();
|
||||
}
|
||||
|
||||
abstract protected function executeQuery();
|
||||
|
||||
final public function getRawData() {
|
||||
return $this->fileContent->getCorpus();
|
||||
}
|
||||
|
|
|
@ -6,12 +6,11 @@
|
|||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/base');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
|
||||
phutil_require_module('phabricator', 'applications/repository/storage/commit');
|
||||
phutil_require_module('phabricator', 'applications/repository/storage/commitdata');
|
||||
|
||||
phutil_require_module('phutil', 'symbols');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue