From 9b4295ed6051aff6bcef406db3ea75b9f41e32eb Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 22 Feb 2018 19:16:45 -0800 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 6 ++ .../PhabricatorHarbormasterApplication.php | 4 ++ ...HarbormasterBuildLogDownloadController.php | 62 +++++++++++++++++++ .../HarbormasterBuildLogViewController.php | 44 +++++++++++++ ...HarbormasterManagementWriteLogWorkflow.php | 7 ++- .../phid/HarbormasterBuildLogPHIDType.php | 4 +- .../storage/build/HarbormasterBuildLog.php | 5 ++ .../view/HarbormasterBuildLogView.php | 45 ++++++++++++++ 8 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 src/applications/harbormaster/controller/HarbormasterBuildLogDownloadController.php create mode 100644 src/applications/harbormaster/controller/HarbormasterBuildLogViewController.php create mode 100644 src/applications/harbormaster/view/HarbormasterBuildLogView.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f22f7f6730..451305d7fb 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1227,8 +1227,11 @@ phutil_register_library_map(array( 'HarbormasterBuildLog' => 'applications/harbormaster/storage/build/HarbormasterBuildLog.php', 'HarbormasterBuildLogChunk' => 'applications/harbormaster/storage/build/HarbormasterBuildLogChunk.php', 'HarbormasterBuildLogChunkIterator' => 'applications/harbormaster/storage/build/HarbormasterBuildLogChunkIterator.php', + 'HarbormasterBuildLogDownloadController' => 'applications/harbormaster/controller/HarbormasterBuildLogDownloadController.php', 'HarbormasterBuildLogPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php', 'HarbormasterBuildLogQuery' => 'applications/harbormaster/query/HarbormasterBuildLogQuery.php', + 'HarbormasterBuildLogView' => 'applications/harbormaster/view/HarbormasterBuildLogView.php', + 'HarbormasterBuildLogViewController' => 'applications/harbormaster/controller/HarbormasterBuildLogViewController.php', 'HarbormasterBuildMessage' => 'applications/harbormaster/storage/HarbormasterBuildMessage.php', 'HarbormasterBuildMessageQuery' => 'applications/harbormaster/query/HarbormasterBuildMessageQuery.php', 'HarbormasterBuildPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildPHIDType.php', @@ -6511,8 +6514,11 @@ phutil_register_library_map(array( ), 'HarbormasterBuildLogChunk' => 'HarbormasterDAO', 'HarbormasterBuildLogChunkIterator' => 'PhutilBufferedIterator', + 'HarbormasterBuildLogDownloadController' => 'HarbormasterController', 'HarbormasterBuildLogPHIDType' => 'PhabricatorPHIDType', 'HarbormasterBuildLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'HarbormasterBuildLogView' => 'AphrontView', + 'HarbormasterBuildLogViewController' => 'HarbormasterController', 'HarbormasterBuildMessage' => array( 'HarbormasterDAO', 'PhabricatorPolicyInterface', diff --git a/src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php b/src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php index ed164b2d3b..b4f62d8e22 100644 --- a/src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php +++ b/src/applications/harbormaster/application/PhabricatorHarbormasterApplication.php @@ -96,6 +96,10 @@ final class PhabricatorHarbormasterApplication extends PhabricatorApplication { 'circleci/' => 'HarbormasterCircleCIHookController', 'buildkite/' => 'HarbormasterBuildkiteHookController', ), + 'log/' => array( + 'view/(?P\d+)/' => 'HarbormasterBuildLogViewController', + 'download/(?P\d+)/' => 'HarbormasterBuildLogDownloadController', + ), ), ); } diff --git a/src/applications/harbormaster/controller/HarbormasterBuildLogDownloadController.php b/src/applications/harbormaster/controller/HarbormasterBuildLogDownloadController.php new file mode 100644 index 0000000000..6bdd04edc3 --- /dev/null +++ b/src/applications/harbormaster/controller/HarbormasterBuildLogDownloadController.php @@ -0,0 +1,62 @@ +getRequest(); + $viewer = $request->getUser(); + + $id = $request->getURIData('id'); + + $log = id(new HarbormasterBuildLogQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->executeOne(); + if (!$log) { + return new Aphront404Response(); + } + + $cancel_uri = $log->getURI(); + $file_phid = $log->getFilePHID(); + + if (!$file_phid) { + return $this->newDialog() + ->setTitle(pht('Log Not Finalized')) + ->appendParagraph( + pht( + 'Logs must be fully written and processed before they can be '. + 'downloaded. This log is still being written or processed.')) + ->addCancelButton($cancel_uri, pht('Wait Patiently')); + } + + $file = id(new PhabricatorFileQuery()) + ->setViewer($viewer) + ->withPHIDs(array($file_phid)) + ->executeOne(); + if (!$file) { + return $this->newDialog() + ->setTitle(pht('Unable to Load File')) + ->appendParagraph( + pht( + 'Unable to load the file for this log. The file may have been '. + 'destroyed.')) + ->addCancelButton($cancel_uri); + } + + $size = $file->getByteSize(); + + return $this->newDialog() + ->setTitle(pht('Download Build Log')) + ->appendParagraph( + pht( + 'This log has a total size of %s. If you insist, you may '. + 'download it.', + phutil_tag('strong', array(), phutil_format_bytes($size)))) + ->setDisableWorkflowOnSubmit(true) + ->addSubmitButton(pht('Download Log')) + ->setSubmitURI($file->getDownloadURI()) + ->addCancelButton($cancel_uri, pht('Done')); + } + +} diff --git a/src/applications/harbormaster/controller/HarbormasterBuildLogViewController.php b/src/applications/harbormaster/controller/HarbormasterBuildLogViewController.php new file mode 100644 index 0000000000..084c48d1f1 --- /dev/null +++ b/src/applications/harbormaster/controller/HarbormasterBuildLogViewController.php @@ -0,0 +1,44 @@ +getRequest(); + $viewer = $request->getUser(); + + $id = $request->getURIData('id'); + + $log = id(new HarbormasterBuildLogQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->executeOne(); + if (!$log) { + return new Aphront404Response(); + } + + $page_title = pht('Build Log %d', $log->getID()); + + $log_view = id(new HarbormasterBuildLogView()) + ->setViewer($viewer) + ->setBuildLog($log); + + $crumbs = $this->buildApplicationCrumbs() + ->addTextCrumb(pht('Build Logs')) + ->addTextCrumb($page_title) + ->setBorder(true); + + $page_header = id(new PHUIHeaderView()) + ->setHeader($page_title); + + $page_view = id(new PHUITwoColumnView()) + ->setHeader($page_header) + ->setFooter($log_view); + + return $this->newPage() + ->setTitle($page_title) + ->setCrumbs($crumbs) + ->appendChild($page_view); + } + +} diff --git a/src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php b/src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php index 367fe4fc78..b680b382aa 100644 --- a/src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php +++ b/src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php @@ -44,9 +44,14 @@ final class HarbormasterManagementWriteLogWorkflow $log = HarbormasterBuildLog::initializeNewBuildLog($target); $log->openBuildLog(); + echo tsprintf( + "%s\n\n __%s__\n\n", + pht('Opened a new build log:'), + PhabricatorEnv::getURI($log->getURI())); + echo tsprintf( "%s\n", - pht('Reading log from stdin...')); + pht('Reading log content from stdin...')); $content = file_get_contents('php://stdin'); $log->append($content); diff --git a/src/applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php b/src/applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php index dd110556b1..a2fa58fe79 100644 --- a/src/applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php +++ b/src/applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php @@ -32,7 +32,9 @@ final class HarbormasterBuildLogPHIDType extends PhabricatorPHIDType { foreach ($handles as $phid => $handle) { $build_log = $objects[$phid]; - $handle->setName(pht('Build Log %d', $build_log->getID())); + $handle + ->setName(pht('Build Log %d', $build_log->getID())) + ->setURI($build_log->getURI()); } } diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php index ca8f0bb9d5..17249313eb 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php @@ -290,6 +290,11 @@ final class HarbormasterBuildLog ->save(); } + public function getURI() { + $id = $this->getID(); + return "/harbormaster/log/view/{$id}/"; + } + /* -( PhabricatorPolicyInterface )----------------------------------------- */ diff --git a/src/applications/harbormaster/view/HarbormasterBuildLogView.php b/src/applications/harbormaster/view/HarbormasterBuildLogView.php new file mode 100644 index 0000000000..7543524285 --- /dev/null +++ b/src/applications/harbormaster/view/HarbormasterBuildLogView.php @@ -0,0 +1,45 @@ +log = $log; + return $this; + } + + public function getBuildLog() { + return $this->log; + } + + public function render() { + $viewer = $this->getViewer(); + $log = $this->getBuildLog(); + $id = $log->getID(); + + $header = id(new PHUIHeaderView()) + ->setViewer($viewer) + ->setHeader(pht('Build Log %d', $id)); + + $download_uri = "/harbormaster/log/download/{$id}/"; + + $download_button = id(new PHUIButtonView()) + ->setTag('a') + ->setHref($download_uri) + ->setIcon('fa-download') + ->setDisabled(!$log->getFilePHID()) + ->setWorkflow(true) + ->setText(pht('Download Log')); + + $header->addActionLink($download_button); + + $box_view = id(new PHUIObjectBoxView()) + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) + ->setHeader($header) + ->appendChild('...'); + + return $box_view; + } + +}