@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.

Add a very basic standalone view for build logs with a "Download Log" button

Summary: Depends on D19132. Ref T13088. This implements an extremely skeletal dedicated log page with a more-or-less functional "Download Log" button.

Test Plan: Downloaded a recent log. Tried to download an old (un-finalized) log, couldn't. Used `bin/harbormaster write-log` to get a convenient standalone link to a log.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13088

Differential Revision: https://secure.phabricator.com/D19133

+175 -2
+6
src/__phutil_library_map__.php
··· 1227 1227 'HarbormasterBuildLog' => 'applications/harbormaster/storage/build/HarbormasterBuildLog.php', 1228 1228 'HarbormasterBuildLogChunk' => 'applications/harbormaster/storage/build/HarbormasterBuildLogChunk.php', 1229 1229 'HarbormasterBuildLogChunkIterator' => 'applications/harbormaster/storage/build/HarbormasterBuildLogChunkIterator.php', 1230 + 'HarbormasterBuildLogDownloadController' => 'applications/harbormaster/controller/HarbormasterBuildLogDownloadController.php', 1230 1231 'HarbormasterBuildLogPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php', 1231 1232 'HarbormasterBuildLogQuery' => 'applications/harbormaster/query/HarbormasterBuildLogQuery.php', 1233 + 'HarbormasterBuildLogView' => 'applications/harbormaster/view/HarbormasterBuildLogView.php', 1234 + 'HarbormasterBuildLogViewController' => 'applications/harbormaster/controller/HarbormasterBuildLogViewController.php', 1232 1235 'HarbormasterBuildMessage' => 'applications/harbormaster/storage/HarbormasterBuildMessage.php', 1233 1236 'HarbormasterBuildMessageQuery' => 'applications/harbormaster/query/HarbormasterBuildMessageQuery.php', 1234 1237 'HarbormasterBuildPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildPHIDType.php', ··· 6511 6514 ), 6512 6515 'HarbormasterBuildLogChunk' => 'HarbormasterDAO', 6513 6516 'HarbormasterBuildLogChunkIterator' => 'PhutilBufferedIterator', 6517 + 'HarbormasterBuildLogDownloadController' => 'HarbormasterController', 6514 6518 'HarbormasterBuildLogPHIDType' => 'PhabricatorPHIDType', 6515 6519 'HarbormasterBuildLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6520 + 'HarbormasterBuildLogView' => 'AphrontView', 6521 + 'HarbormasterBuildLogViewController' => 'HarbormasterController', 6516 6522 'HarbormasterBuildMessage' => array( 6517 6523 'HarbormasterDAO', 6518 6524 'PhabricatorPolicyInterface',
+4
src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php
··· 96 96 'circleci/' => 'HarbormasterCircleCIHookController', 97 97 'buildkite/' => 'HarbormasterBuildkiteHookController', 98 98 ), 99 + 'log/' => array( 100 + 'view/(?P<id>\d+)/' => 'HarbormasterBuildLogViewController', 101 + 'download/(?P<id>\d+)/' => 'HarbormasterBuildLogDownloadController', 102 + ), 99 103 ), 100 104 ); 101 105 }
+62
src/applications/harbormaster/controller/HarbormasterBuildLogDownloadController.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildLogDownloadController 4 + extends HarbormasterController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $request = $this->getRequest(); 8 + $viewer = $request->getUser(); 9 + 10 + $id = $request->getURIData('id'); 11 + 12 + $log = id(new HarbormasterBuildLogQuery()) 13 + ->setViewer($viewer) 14 + ->withIDs(array($id)) 15 + ->executeOne(); 16 + if (!$log) { 17 + return new Aphront404Response(); 18 + } 19 + 20 + $cancel_uri = $log->getURI(); 21 + $file_phid = $log->getFilePHID(); 22 + 23 + if (!$file_phid) { 24 + return $this->newDialog() 25 + ->setTitle(pht('Log Not Finalized')) 26 + ->appendParagraph( 27 + pht( 28 + 'Logs must be fully written and processed before they can be '. 29 + 'downloaded. This log is still being written or processed.')) 30 + ->addCancelButton($cancel_uri, pht('Wait Patiently')); 31 + } 32 + 33 + $file = id(new PhabricatorFileQuery()) 34 + ->setViewer($viewer) 35 + ->withPHIDs(array($file_phid)) 36 + ->executeOne(); 37 + if (!$file) { 38 + return $this->newDialog() 39 + ->setTitle(pht('Unable to Load File')) 40 + ->appendParagraph( 41 + pht( 42 + 'Unable to load the file for this log. The file may have been '. 43 + 'destroyed.')) 44 + ->addCancelButton($cancel_uri); 45 + } 46 + 47 + $size = $file->getByteSize(); 48 + 49 + return $this->newDialog() 50 + ->setTitle(pht('Download Build Log')) 51 + ->appendParagraph( 52 + pht( 53 + 'This log has a total size of %s. If you insist, you may '. 54 + 'download it.', 55 + phutil_tag('strong', array(), phutil_format_bytes($size)))) 56 + ->setDisableWorkflowOnSubmit(true) 57 + ->addSubmitButton(pht('Download Log')) 58 + ->setSubmitURI($file->getDownloadURI()) 59 + ->addCancelButton($cancel_uri, pht('Done')); 60 + } 61 + 62 + }
+44
src/applications/harbormaster/controller/HarbormasterBuildLogViewController.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildLogViewController 4 + extends HarbormasterController { 5 + 6 + public function handleRequest(AphrontRequest $request) { 7 + $request = $this->getRequest(); 8 + $viewer = $request->getUser(); 9 + 10 + $id = $request->getURIData('id'); 11 + 12 + $log = id(new HarbormasterBuildLogQuery()) 13 + ->setViewer($viewer) 14 + ->withIDs(array($id)) 15 + ->executeOne(); 16 + if (!$log) { 17 + return new Aphront404Response(); 18 + } 19 + 20 + $page_title = pht('Build Log %d', $log->getID()); 21 + 22 + $log_view = id(new HarbormasterBuildLogView()) 23 + ->setViewer($viewer) 24 + ->setBuildLog($log); 25 + 26 + $crumbs = $this->buildApplicationCrumbs() 27 + ->addTextCrumb(pht('Build Logs')) 28 + ->addTextCrumb($page_title) 29 + ->setBorder(true); 30 + 31 + $page_header = id(new PHUIHeaderView()) 32 + ->setHeader($page_title); 33 + 34 + $page_view = id(new PHUITwoColumnView()) 35 + ->setHeader($page_header) 36 + ->setFooter($log_view); 37 + 38 + return $this->newPage() 39 + ->setTitle($page_title) 40 + ->setCrumbs($crumbs) 41 + ->appendChild($page_view); 42 + } 43 + 44 + }
+6 -1
src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php
··· 45 45 $log->openBuildLog(); 46 46 47 47 echo tsprintf( 48 + "%s\n\n __%s__\n\n", 49 + pht('Opened a new build log:'), 50 + PhabricatorEnv::getURI($log->getURI())); 51 + 52 + echo tsprintf( 48 53 "%s\n", 49 - pht('Reading log from stdin...')); 54 + pht('Reading log content from stdin...')); 50 55 51 56 $content = file_get_contents('php://stdin'); 52 57 $log->append($content);
+3 -1
src/applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php
··· 32 32 foreach ($handles as $phid => $handle) { 33 33 $build_log = $objects[$phid]; 34 34 35 - $handle->setName(pht('Build Log %d', $build_log->getID())); 35 + $handle 36 + ->setName(pht('Build Log %d', $build_log->getID())) 37 + ->setURI($build_log->getURI()); 36 38 } 37 39 } 38 40
+5
src/applications/harbormaster/storage/build/HarbormasterBuildLog.php
··· 290 290 ->save(); 291 291 } 292 292 293 + public function getURI() { 294 + $id = $this->getID(); 295 + return "/harbormaster/log/view/{$id}/"; 296 + } 297 + 293 298 294 299 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 295 300
+45
src/applications/harbormaster/view/HarbormasterBuildLogView.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildLogView extends AphrontView { 4 + 5 + private $log; 6 + 7 + public function setBuildLog(HarbormasterBuildLog $log) { 8 + $this->log = $log; 9 + return $this; 10 + } 11 + 12 + public function getBuildLog() { 13 + return $this->log; 14 + } 15 + 16 + public function render() { 17 + $viewer = $this->getViewer(); 18 + $log = $this->getBuildLog(); 19 + $id = $log->getID(); 20 + 21 + $header = id(new PHUIHeaderView()) 22 + ->setViewer($viewer) 23 + ->setHeader(pht('Build Log %d', $id)); 24 + 25 + $download_uri = "/harbormaster/log/download/{$id}/"; 26 + 27 + $download_button = id(new PHUIButtonView()) 28 + ->setTag('a') 29 + ->setHref($download_uri) 30 + ->setIcon('fa-download') 31 + ->setDisabled(!$log->getFilePHID()) 32 + ->setWorkflow(true) 33 + ->setText(pht('Download Log')); 34 + 35 + $header->addActionLink($download_button); 36 + 37 + $box_view = id(new PHUIObjectBoxView()) 38 + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 39 + ->setHeader($header) 40 + ->appendChild('...'); 41 + 42 + return $box_view; 43 + } 44 + 45 + }