@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+130 -106
+2
src/__phutil_library_map__.php
··· 160 160 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_lastmodifiedquery_Method.php', 161 161 'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_mergedcommitsquery_Method.php', 162 162 'ConduitAPI_diffusion_rawdiffquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_rawdiffquery_Method.php', 163 + 'ConduitAPI_diffusion_readmequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_readmequery_Method.php', 163 164 'ConduitAPI_diffusion_refsquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_refsquery_Method.php', 164 165 'ConduitAPI_diffusion_searchquery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_searchquery_Method.php', 165 166 'ConduitAPI_diffusion_stablecommitnamequery_Method' => 'applications/diffusion/conduit/ConduitAPI_diffusion_stablecommitnamequery_Method.php', ··· 1967 1968 'ConduitAPI_diffusion_lastmodifiedquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1968 1969 'ConduitAPI_diffusion_mergedcommitsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1969 1970 'ConduitAPI_diffusion_rawdiffquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1971 + 'ConduitAPI_diffusion_readmequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1970 1972 'ConduitAPI_diffusion_refsquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1971 1973 'ConduitAPI_diffusion_searchquery_Method' => 'ConduitAPI_diffusion_abstractquery_Method', 1972 1974 'ConduitAPI_diffusion_stablecommitnamequery_Method' => 'ConduitAPI_diffusion_abstractquery_Method',
-83
src/applications/diffusion/conduit/ConduitAPI_diffusion_browsequery_Method.php
··· 21 21 'path' => 'optional string', 22 22 'commit' => 'optional string', 23 23 'needValidityOnly' => 'optional bool', 24 - 'renderReadme' => 'optional bool', 25 24 ); 26 25 } 27 26 28 27 protected function getResult(ConduitAPIRequest $request) { 29 28 $result = parent::getResult($request); 30 - if ($request->getValue('renderReadme', false)) { 31 - $readme = $this->renderReadme($request, $result); 32 - } 33 29 return $result->toDictionary(); 34 - } 35 - 36 - final private function renderReadme( 37 - ConduitAPIRequest $request, 38 - DiffusionBrowseResultSet $result) { 39 - $drequest = $this->getDiffusionRequest(); 40 - 41 - $readme = null; 42 - foreach ($result->getPaths() as $result_path) { 43 - $file_type = $result_path->getFileType(); 44 - if (($file_type != ArcanistDiffChangeType::FILE_NORMAL) && 45 - ($file_type != ArcanistDiffChangeType::FILE_TEXT)) { 46 - // Skip directories, etc. 47 - continue; 48 - } 49 - 50 - $path = $result_path->getPath(); 51 - 52 - if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow|\.md)$/i', $path)) { 53 - $readme = $result_path; 54 - break; 55 - } 56 - } 57 - 58 - if (!$readme) { 59 - return null; 60 - } 61 - 62 - $readme_request = DiffusionRequest::newFromDictionary( 63 - array( 64 - 'user' => $request->getUser(), 65 - 'repository' => $drequest->getRepository(), 66 - 'commit' => $drequest->getStableCommitName(), 67 - 'path' => $readme->getFullPath(), 68 - )); 69 - 70 - $file_content = DiffusionFileContent::newFromConduit( 71 - DiffusionQuery::callConduitWithDiffusionRequest( 72 - $request->getUser(), 73 - $readme_request, 74 - 'diffusion.filecontentquery', 75 - array( 76 - 'commit' => $drequest->getStableCommitName(), 77 - 'path' => $readme->getFullPath(), 78 - 'needsBlame' => false, 79 - ))); 80 - $readme_content = $file_content->getCorpus(); 81 - 82 - if (preg_match('/\\.txt$/', $readme->getPath())) { 83 - $readme_content = phutil_escape_html_newlines($readme_content); 84 - 85 - $class = null; 86 - } else if (preg_match('/\\.rainbow$/', $readme->getPath())) { 87 - $highlighter = new PhutilRainbowSyntaxHighlighter(); 88 - $readme_content = $highlighter 89 - ->getHighlightFuture($readme_content) 90 - ->resolve(); 91 - $readme_content = phutil_escape_html_newlines($readme_content); 92 - 93 - require_celerity_resource('syntax-highlighting-css'); 94 - $class = 'remarkup-code'; 95 - } else { 96 - // Markup extensionless files as remarkup so we get links and such. 97 - $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine(); 98 - $engine->setConfig('viewer', $request->getUser()); 99 - $readme_content = $engine->markupText($readme_content); 100 - 101 - $class = 'phabricator-remarkup'; 102 - } 103 - 104 - $readme_content = phutil_tag( 105 - 'div', 106 - array( 107 - 'class' => $class, 108 - ), 109 - $readme_content); 110 - 111 - $result->setReadmeContent($readme_content); 112 - return $result; 113 30 } 114 31 115 32 protected function getGitResult(ConduitAPIRequest $request) {
+106
src/applications/diffusion/conduit/ConduitAPI_diffusion_readmequery_Method.php
··· 1 + <?php 2 + 3 + /** 4 + * @group conduit 5 + */ 6 + final class ConduitAPI_diffusion_readmequery_Method 7 + extends ConduitAPI_diffusion_abstractquery_Method { 8 + 9 + public function getMethodDescription() { 10 + return 11 + 'Retrieve any "readme" that can be found for a set of paths in '. 12 + 'repository.'; 13 + } 14 + 15 + public function defineReturnType() { 16 + return 'string'; 17 + } 18 + 19 + protected function defineCustomParamTypes() { 20 + return array( 21 + 'paths' => 'required array <string>', 22 + ); 23 + } 24 + 25 + protected function getResult(ConduitAPIRequest $request) { 26 + $drequest = $this->getDiffusionRequest(); 27 + $path_dicts = $request->getValue('paths', array()); 28 + $paths = array(); 29 + foreach ($path_dicts as $dict) { 30 + $paths[] = DiffusionRepositoryPath::newFromDictionary($dict); 31 + } 32 + 33 + $readme = ''; 34 + foreach ($paths as $result_path) { 35 + $file_type = $result_path->getFileType(); 36 + if (($file_type != ArcanistDiffChangeType::FILE_NORMAL) && 37 + ($file_type != ArcanistDiffChangeType::FILE_TEXT)) { 38 + // Skip directories, etc. 39 + continue; 40 + } 41 + 42 + $path = $result_path->getPath(); 43 + 44 + if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow|\.md)$/i', $path)) { 45 + $readme = $result_path; 46 + break; 47 + } 48 + } 49 + 50 + if (!$readme) { 51 + return ''; 52 + } 53 + 54 + $readme_request = DiffusionRequest::newFromDictionary( 55 + array( 56 + 'user' => $request->getUser(), 57 + 'repository' => $drequest->getRepository(), 58 + 'commit' => $drequest->getStableCommitName(), 59 + 'path' => $readme->getFullPath(), 60 + )); 61 + 62 + $file_content = DiffusionFileContent::newFromConduit( 63 + DiffusionQuery::callConduitWithDiffusionRequest( 64 + $request->getUser(), 65 + $readme_request, 66 + 'diffusion.filecontentquery', 67 + array( 68 + 'commit' => $drequest->getStableCommitName(), 69 + 'path' => $readme->getFullPath(), 70 + 'needsBlame' => false, 71 + ))); 72 + $readme_content = $file_content->getCorpus(); 73 + 74 + if (preg_match('/\\.txt$/', $readme->getPath())) { 75 + $readme_content = phutil_escape_html_newlines($readme_content); 76 + 77 + $class = null; 78 + } else if (preg_match('/\\.rainbow$/', $readme->getPath())) { 79 + $highlighter = new PhutilRainbowSyntaxHighlighter(); 80 + $readme_content = $highlighter 81 + ->getHighlightFuture($readme_content) 82 + ->resolve(); 83 + $readme_content = phutil_escape_html_newlines($readme_content); 84 + 85 + require_celerity_resource('syntax-highlighting-css'); 86 + $class = 'remarkup-code'; 87 + } else { 88 + // Markup extensionless files as remarkup so we get links and such. 89 + $engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine(); 90 + $engine->setConfig('viewer', $request->getUser()); 91 + $readme_content = $engine->markupText($readme_content); 92 + 93 + $class = 'phabricator-remarkup'; 94 + } 95 + 96 + $readme_content = phutil_tag( 97 + 'div', 98 + array( 99 + 'class' => $class, 100 + ), 101 + $readme_content); 102 + 103 + return $readme_content; 104 + } 105 + 106 + }
+5 -2
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 15 15 array( 16 16 'path' => $drequest->getPath(), 17 17 'commit' => $drequest->getCommit(), 18 - 'renderReadme' => true, 19 18 ))); 20 19 $reason = $results->getReasonForEmptyResultSet(); 21 20 $is_file = ($reason == DiffusionBrowseResultSet::REASON_IS_FILE); ··· 84 83 85 84 $content[] = $this->buildOpenRevisions(); 86 85 87 - $readme = $results->getReadmeContent(); 86 + $readme = $this->callConduitWithDiffusionRequest( 87 + 'diffusion.readmequery', 88 + array( 89 + 'paths' => $results->getPathDicts() 90 + )); 88 91 if ($readme) { 89 92 $box = new PHUIBoxView(); 90 93 $box->setShadow(true);
+6 -4
src/applications/diffusion/controller/DiffusionRepositoryController.php
··· 28 28 array( 29 29 'path' => $drequest->getPath(), 30 30 'commit' => $drequest->getCommit(), 31 - 'renderReadme' => true, 32 31 ))); 33 32 $browse_paths = $browse_results->getPaths(); 34 33 35 34 $phids = array(); 36 - 37 35 foreach ($history as $item) { 38 36 $data = $item->getCommitData(); 39 37 if ($data) { ··· 57 55 } 58 56 } 59 57 } 60 - 61 58 $phids = array_keys($phids); 62 59 $handles = $this->loadViewerHandles($phids); 60 + 61 + $readme = $this->callConduitWithDiffusionRequest( 62 + 'diffusion.readmequery', 63 + array( 64 + 'paths' => $browse_results->getPathDicts() 65 + )); 63 66 64 67 $history_table = new DiffusionHistoryTableView(); 65 68 $history_table->setUser($this->getRequest()->getUser()); ··· 109 112 110 113 $content[] = $this->buildBranchListTable($drequest); 111 114 112 - $readme = $browse_results->getReadmeContent(); 113 115 if ($readme) { 114 116 $box = new PHUIBoxView(); 115 117 $box->setShadow(true);
+11 -17
src/applications/diffusion/data/DiffusionBrowseResultSet.php
··· 14 14 private $reasonForEmptyResultSet; 15 15 private $existedAtCommit; 16 16 private $deletedAtCommit; 17 - private $readmeContent; 18 17 19 18 public function setPaths(array $paths) { 20 19 assert_instances_of($paths, 'DiffusionRepositoryPath'); ··· 57 56 return $this->deletedAtCommit; 58 57 } 59 58 60 - public function setReadmeContent($readme_content) { 61 - $this->readmeContent = $readme_content; 62 - return $this; 63 - } 64 - public function getReadmeContent() { 65 - return $this->readmeContent; 66 - } 67 - 68 59 public function toDictionary() { 69 - $paths = $this->getPaths(); 70 - if ($paths) { 71 - $paths = mpull($paths, 'toDictionary'); 72 - } 60 + $paths = $this->getPathDicts(); 73 61 74 62 return array( 75 63 'paths' => $paths, 76 64 'isValidResults' => $this->isValidResults(), 77 65 'reasonForEmptyResultSet' => $this->getReasonForEmptyResultSet(), 78 66 'existedAtCommit' => $this->getExistedAtCommit(), 79 - 'deletedAtCommit' => $this->getDeletedAtCommit(), 80 - 'readmeContent' => $this->getReadmeContent()); 67 + 'deletedAtCommit' => $this->getDeletedAtCommit()); 68 + } 69 + 70 + public function getPathDicts() { 71 + $paths = $this->getPaths(); 72 + if ($paths) { 73 + return mpull($paths, 'toDictionary'); 74 + } 75 + return array(); 81 76 } 82 77 83 78 public static function newFromConduit(array $data) { ··· 91 86 ->setIsValidResults($data['isValidResults']) 92 87 ->setReasonForEmptyResultSet($data['reasonForEmptyResultSet']) 93 88 ->setExistedAtCommit($data['existedAtCommit']) 94 - ->setDeletedAtCommit($data['deletedAtCommit']) 95 - ->setReadmeContent($data['readmeContent']); 89 + ->setDeletedAtCommit($data['deletedAtCommit']); 96 90 } 97 91 }