mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-11 06:18:33 +01:00
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
This commit is contained in:
parent
8a2604cf06
commit
9b4295ed60
8 changed files with 175 additions and 2 deletions
|
@ -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',
|
||||
|
|
|
@ -96,6 +96,10 @@ final class PhabricatorHarbormasterApplication extends PhabricatorApplication {
|
|||
'circleci/' => 'HarbormasterCircleCIHookController',
|
||||
'buildkite/' => 'HarbormasterBuildkiteHookController',
|
||||
),
|
||||
'log/' => array(
|
||||
'view/(?P<id>\d+)/' => 'HarbormasterBuildLogViewController',
|
||||
'download/(?P<id>\d+)/' => 'HarbormasterBuildLogDownloadController',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterBuildLogDownloadController
|
||||
extends HarbormasterController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$request = $this->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'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterBuildLogViewController
|
||||
extends HarbormasterController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$request = $this->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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -290,6 +290,11 @@ final class HarbormasterBuildLog
|
|||
->save();
|
||||
}
|
||||
|
||||
public function getURI() {
|
||||
$id = $this->getID();
|
||||
return "/harbormaster/log/view/{$id}/";
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterBuildLogView extends AphrontView {
|
||||
|
||||
private $log;
|
||||
|
||||
public function setBuildLog(HarbormasterBuildLog $log) {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue