mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
Diffusion - break out readme query all on its own
Summary: nice title. Ref T2784. Fixes T3171. Test Plan: For all 3 VCS types, viewed phabricator repository and saw readme. browsed said repository and saw readme. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2784, T3171 Differential Revision: https://secure.phabricator.com/D5993
This commit is contained in:
parent
5d495ebbad
commit
f6b393d529
6 changed files with 130 additions and 106 deletions
|
@ -160,6 +160,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_lastmodifiedquery_Method.php',
|
'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_lastmodifiedquery_Method.php',
|
||||||
'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_mergedcommitsquery_Method.php',
|
'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_mergedcommitsquery_Method.php',
|
||||||
'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php',
|
'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php',
|
||||||
|
'ConduitAPI_diffusion_readmequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_readmequery_Method.php',
|
||||||
'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php',
|
'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php',
|
||||||
'ConduitAPI_diffusion_searchquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_searchquery_Method.php',
|
'ConduitAPI_diffusion_searchquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_searchquery_Method.php',
|
||||||
'ConduitAPI_diffusion_stablecommitnamequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_stablecommitnamequery_Method.php',
|
'ConduitAPI_diffusion_stablecommitnamequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_stablecommitnamequery_Method.php',
|
||||||
|
@ -1967,6 +1968,7 @@ phutil_register_library_map(array(
|
||||||
'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
|
'ConduitAPI_diffusion_readmequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_searchquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_searchquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
'ConduitAPI_diffusion_stablecommitnamequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
'ConduitAPI_diffusion_stablecommitnamequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
|
||||||
|
|
|
@ -21,97 +21,14 @@ final class ConduitAPI_diffusion_browsequery_Method
|
||||||
'path' => 'optional string',
|
'path' => 'optional string',
|
||||||
'commit' => 'optional string',
|
'commit' => 'optional string',
|
||||||
'needValidityOnly' => 'optional bool',
|
'needValidityOnly' => 'optional bool',
|
||||||
'renderReadme' => 'optional bool',
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getResult(ConduitAPIRequest $request) {
|
protected function getResult(ConduitAPIRequest $request) {
|
||||||
$result = parent::getResult($request);
|
$result = parent::getResult($request);
|
||||||
if ($request->getValue('renderReadme', false)) {
|
|
||||||
$readme = $this->renderReadme($request, $result);
|
|
||||||
}
|
|
||||||
return $result->toDictionary();
|
return $result->toDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
final private function renderReadme(
|
|
||||||
ConduitAPIRequest $request,
|
|
||||||
DiffusionBrowseResultSet $result) {
|
|
||||||
$drequest = $this->getDiffusionRequest();
|
|
||||||
|
|
||||||
$readme = null;
|
|
||||||
foreach ($result->getPaths() as $result_path) {
|
|
||||||
$file_type = $result_path->getFileType();
|
|
||||||
if (($file_type != ArcanistDiffChangeType::FILE_NORMAL) &&
|
|
||||||
($file_type != ArcanistDiffChangeType::FILE_TEXT)) {
|
|
||||||
// Skip directories, etc.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$path = $result_path->getPath();
|
|
||||||
|
|
||||||
if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow|\.md)$/i', $path)) {
|
|
||||||
$readme = $result_path;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$readme) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$readme_request = DiffusionRequest::newFromDictionary(
|
|
||||||
array(
|
|
||||||
'user' => $request->getUser(),
|
|
||||||
'repository' => $drequest->getRepository(),
|
|
||||||
'commit' => $drequest->getStableCommitName(),
|
|
||||||
'path' => $readme->getFullPath(),
|
|
||||||
));
|
|
||||||
|
|
||||||
$file_content = DiffusionFileContent::newFromConduit(
|
|
||||||
DiffusionQuery::callConduitWithDiffusionRequest(
|
|
||||||
$request->getUser(),
|
|
||||||
$readme_request,
|
|
||||||
'diffusion.filecontentquery',
|
|
||||||
array(
|
|
||||||
'commit' => $drequest->getStableCommitName(),
|
|
||||||
'path' => $readme->getFullPath(),
|
|
||||||
'needsBlame' => false,
|
|
||||||
)));
|
|
||||||
$readme_content = $file_content->getCorpus();
|
|
||||||
|
|
||||||
if (preg_match('/\\.txt$/', $readme->getPath())) {
|
|
||||||
$readme_content = phutil_escape_html_newlines($readme_content);
|
|
||||||
|
|
||||||
$class = null;
|
|
||||||
} else if (preg_match('/\\.rainbow$/', $readme->getPath())) {
|
|
||||||
$highlighter = new PhutilRainbowSyntaxHighlighter();
|
|
||||||
$readme_content = $highlighter
|
|
||||||
->getHighlightFuture($readme_content)
|
|
||||||
->resolve();
|
|
||||||
$readme_content = phutil_escape_html_newlines($readme_content);
|
|
||||||
|
|
||||||
require_celerity_resource('syntax-highlighting-css');
|
|
||||||
$class = 'remarkup-code';
|
|
||||||
} else {
|
|
||||||
// Markup extensionless files as remarkup so we get links and such.
|
|
||||||
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
|
|
||||||
$engine->setConfig('viewer', $request->getUser());
|
|
||||||
$readme_content = $engine->markupText($readme_content);
|
|
||||||
|
|
||||||
$class = 'phabricator-remarkup';
|
|
||||||
}
|
|
||||||
|
|
||||||
$readme_content = phutil_tag(
|
|
||||||
'div',
|
|
||||||
array(
|
|
||||||
'class' => $class,
|
|
||||||
),
|
|
||||||
$readme_content);
|
|
||||||
|
|
||||||
$result->setReadmeContent($readme_content);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getGitResult(ConduitAPIRequest $request) {
|
protected function getGitResult(ConduitAPIRequest $request) {
|
||||||
$drequest = $this->getDiffusionRequest();
|
$drequest = $this->getDiffusionRequest();
|
||||||
$repository = $drequest->getRepository();
|
$repository = $drequest->getRepository();
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group conduit
|
||||||
|
*/
|
||||||
|
final class ConduitAPI_diffusion_readmequery_Method
|
||||||
|
extends ConduitAPI_diffusion_abstractquery_Method {
|
||||||
|
|
||||||
|
public function getMethodDescription() {
|
||||||
|
return
|
||||||
|
'Retrieve any "readme" that can be found for a set of paths in '.
|
||||||
|
'repository.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defineReturnType() {
|
||||||
|
return 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function defineCustomParamTypes() {
|
||||||
|
return array(
|
||||||
|
'paths' => 'required array <string>',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getResult(ConduitAPIRequest $request) {
|
||||||
|
$drequest = $this->getDiffusionRequest();
|
||||||
|
$path_dicts = $request->getValue('paths', array());
|
||||||
|
$paths = array();
|
||||||
|
foreach ($path_dicts as $dict) {
|
||||||
|
$paths[] = DiffusionRepositoryPath::newFromDictionary($dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
$readme = '';
|
||||||
|
foreach ($paths as $result_path) {
|
||||||
|
$file_type = $result_path->getFileType();
|
||||||
|
if (($file_type != ArcanistDiffChangeType::FILE_NORMAL) &&
|
||||||
|
($file_type != ArcanistDiffChangeType::FILE_TEXT)) {
|
||||||
|
// Skip directories, etc.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = $result_path->getPath();
|
||||||
|
|
||||||
|
if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow|\.md)$/i', $path)) {
|
||||||
|
$readme = $result_path;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$readme) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$readme_request = DiffusionRequest::newFromDictionary(
|
||||||
|
array(
|
||||||
|
'user' => $request->getUser(),
|
||||||
|
'repository' => $drequest->getRepository(),
|
||||||
|
'commit' => $drequest->getStableCommitName(),
|
||||||
|
'path' => $readme->getFullPath(),
|
||||||
|
));
|
||||||
|
|
||||||
|
$file_content = DiffusionFileContent::newFromConduit(
|
||||||
|
DiffusionQuery::callConduitWithDiffusionRequest(
|
||||||
|
$request->getUser(),
|
||||||
|
$readme_request,
|
||||||
|
'diffusion.filecontentquery',
|
||||||
|
array(
|
||||||
|
'commit' => $drequest->getStableCommitName(),
|
||||||
|
'path' => $readme->getFullPath(),
|
||||||
|
'needsBlame' => false,
|
||||||
|
)));
|
||||||
|
$readme_content = $file_content->getCorpus();
|
||||||
|
|
||||||
|
if (preg_match('/\\.txt$/', $readme->getPath())) {
|
||||||
|
$readme_content = phutil_escape_html_newlines($readme_content);
|
||||||
|
|
||||||
|
$class = null;
|
||||||
|
} else if (preg_match('/\\.rainbow$/', $readme->getPath())) {
|
||||||
|
$highlighter = new PhutilRainbowSyntaxHighlighter();
|
||||||
|
$readme_content = $highlighter
|
||||||
|
->getHighlightFuture($readme_content)
|
||||||
|
->resolve();
|
||||||
|
$readme_content = phutil_escape_html_newlines($readme_content);
|
||||||
|
|
||||||
|
require_celerity_resource('syntax-highlighting-css');
|
||||||
|
$class = 'remarkup-code';
|
||||||
|
} else {
|
||||||
|
// Markup extensionless files as remarkup so we get links and such.
|
||||||
|
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
|
||||||
|
$engine->setConfig('viewer', $request->getUser());
|
||||||
|
$readme_content = $engine->markupText($readme_content);
|
||||||
|
|
||||||
|
$class = 'phabricator-remarkup';
|
||||||
|
}
|
||||||
|
|
||||||
|
$readme_content = phutil_tag(
|
||||||
|
'div',
|
||||||
|
array(
|
||||||
|
'class' => $class,
|
||||||
|
),
|
||||||
|
$readme_content);
|
||||||
|
|
||||||
|
return $readme_content;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
array(
|
array(
|
||||||
'path' => $drequest->getPath(),
|
'path' => $drequest->getPath(),
|
||||||
'commit' => $drequest->getCommit(),
|
'commit' => $drequest->getCommit(),
|
||||||
'renderReadme' => true,
|
|
||||||
)));
|
)));
|
||||||
$reason = $results->getReasonForEmptyResultSet();
|
$reason = $results->getReasonForEmptyResultSet();
|
||||||
$is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE);
|
$is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE);
|
||||||
|
@ -84,7 +83,11 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
|
|
||||||
$content[] = $this->buildOpenRevisions();
|
$content[] = $this->buildOpenRevisions();
|
||||||
|
|
||||||
$readme = $results->getReadmeContent();
|
$readme = $this->callConduitWithDiffusionRequest(
|
||||||
|
'diffusion.readmequery',
|
||||||
|
array(
|
||||||
|
'paths' => $results->getPathDicts()
|
||||||
|
));
|
||||||
if ($readme) {
|
if ($readme) {
|
||||||
$box = new PHUIBoxView();
|
$box = new PHUIBoxView();
|
||||||
$box->setShadow(true);
|
$box->setShadow(true);
|
||||||
|
|
|
@ -28,12 +28,10 @@ final class DiffusionRepositoryController extends DiffusionController {
|
||||||
array(
|
array(
|
||||||
'path' => $drequest->getPath(),
|
'path' => $drequest->getPath(),
|
||||||
'commit' => $drequest->getCommit(),
|
'commit' => $drequest->getCommit(),
|
||||||
'renderReadme' => true,
|
|
||||||
)));
|
)));
|
||||||
$browse_paths = $browse_results->getPaths();
|
$browse_paths = $browse_results->getPaths();
|
||||||
|
|
||||||
$phids = array();
|
$phids = array();
|
||||||
|
|
||||||
foreach ($history as $item) {
|
foreach ($history as $item) {
|
||||||
$data = $item->getCommitData();
|
$data = $item->getCommitData();
|
||||||
if ($data) {
|
if ($data) {
|
||||||
|
@ -57,10 +55,15 @@ final class DiffusionRepositoryController extends DiffusionController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$phids = array_keys($phids);
|
$phids = array_keys($phids);
|
||||||
$handles = $this->loadViewerHandles($phids);
|
$handles = $this->loadViewerHandles($phids);
|
||||||
|
|
||||||
|
$readme = $this->callConduitWithDiffusionRequest(
|
||||||
|
'diffusion.readmequery',
|
||||||
|
array(
|
||||||
|
'paths' => $browse_results->getPathDicts()
|
||||||
|
));
|
||||||
|
|
||||||
$history_table = new DiffusionHistoryTableView();
|
$history_table = new DiffusionHistoryTableView();
|
||||||
$history_table->setUser($this->getRequest()->getUser());
|
$history_table->setUser($this->getRequest()->getUser());
|
||||||
$history_table->setDiffusionRequest($drequest);
|
$history_table->setDiffusionRequest($drequest);
|
||||||
|
@ -109,7 +112,6 @@ final class DiffusionRepositoryController extends DiffusionController {
|
||||||
|
|
||||||
$content[] = $this->buildBranchListTable($drequest);
|
$content[] = $this->buildBranchListTable($drequest);
|
||||||
|
|
||||||
$readme = $browse_results->getReadmeContent();
|
|
||||||
if ($readme) {
|
if ($readme) {
|
||||||
$box = new PHUIBoxView();
|
$box = new PHUIBoxView();
|
||||||
$box->setShadow(true);
|
$box->setShadow(true);
|
||||||
|
|
|
@ -14,7 +14,6 @@ final class DiffusionBrowseResultSet {
|
||||||
private $reasonForEmptyResultSet;
|
private $reasonForEmptyResultSet;
|
||||||
private $existedAtCommit;
|
private $existedAtCommit;
|
||||||
private $deletedAtCommit;
|
private $deletedAtCommit;
|
||||||
private $readmeContent;
|
|
||||||
|
|
||||||
public function setPaths(array $paths) {
|
public function setPaths(array $paths) {
|
||||||
assert_instances_of($paths, 'DiffusionRepositoryPath');
|
assert_instances_of($paths, 'DiffusionRepositoryPath');
|
||||||
|
@ -57,27 +56,23 @@ final class DiffusionBrowseResultSet {
|
||||||
return $this->deletedAtCommit;
|
return $this->deletedAtCommit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setReadmeContent($readme_content) {
|
|
||||||
$this->readmeContent = $readme_content;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
public function getReadmeContent() {
|
|
||||||
return $this->readmeContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toDictionary() {
|
public function toDictionary() {
|
||||||
$paths = $this->getPaths();
|
$paths = $this->getPathDicts();
|
||||||
if ($paths) {
|
|
||||||
$paths = mpull($paths, 'toDictionary');
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'paths' => $paths,
|
'paths' => $paths,
|
||||||
'isValidResults' => $this->isValidResults(),
|
'isValidResults' => $this->isValidResults(),
|
||||||
'reasonForEmptyResultSet' => $this->getReasonForEmptyResultSet(),
|
'reasonForEmptyResultSet' => $this->getReasonForEmptyResultSet(),
|
||||||
'existedAtCommit' => $this->getExistedAtCommit(),
|
'existedAtCommit' => $this->getExistedAtCommit(),
|
||||||
'deletedAtCommit' => $this->getDeletedAtCommit(),
|
'deletedAtCommit' => $this->getDeletedAtCommit());
|
||||||
'readmeContent' => $this->getReadmeContent());
|
}
|
||||||
|
|
||||||
|
public function getPathDicts() {
|
||||||
|
$paths = $this->getPaths();
|
||||||
|
if ($paths) {
|
||||||
|
return mpull($paths, 'toDictionary');
|
||||||
|
}
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function newFromConduit(array $data) {
|
public static function newFromConduit(array $data) {
|
||||||
|
@ -91,7 +86,6 @@ final class DiffusionBrowseResultSet {
|
||||||
->setIsValidResults($data['isValidResults'])
|
->setIsValidResults($data['isValidResults'])
|
||||||
->setReasonForEmptyResultSet($data['reasonForEmptyResultSet'])
|
->setReasonForEmptyResultSet($data['reasonForEmptyResultSet'])
|
||||||
->setExistedAtCommit($data['existedAtCommit'])
|
->setExistedAtCommit($data['existedAtCommit'])
|
||||||
->setDeletedAtCommit($data['deletedAtCommit'])
|
->setDeletedAtCommit($data['deletedAtCommit']);
|
||||||
->setReadmeContent($data['readmeContent']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue