* Put actions related to builds under /build (e.g. /log/<buildid>

becomes /build/<buildid>/log).
This commit is contained in:
Eelco Dolstra 2009-02-25 10:52:41 +00:00
parent f8e162cb18
commit 16acb2754c
4 changed files with 70 additions and 63 deletions

View file

@ -5,10 +5,8 @@ use warnings;
use parent 'Catalyst::Controller';
use Hydra::Helper::Nix;
#
# Sets the actions in this controller to be registered with no prefix
# so they function identically to actions created in MyApp.pm
#
# Put this controller at top-level.
__PACKAGE__->config->{namespace} = '';
@ -26,9 +24,8 @@ sub begin :Private {
sub error {
my ($c, $msg) = @_;
$c->stash->{template} = 'error.tt';
$c->stash->{error} = $msg;
$c->response->status(404);
$c->error($msg);
$c->detach;
}
@ -572,23 +569,34 @@ sub job :Local {
sub default :Path {
my ($self, $c) = @_;
error($c, "Page not found.");
$c->response->status(404);
}
sub build :Local {
sub build : Chained('/') PathPart CaptureArgs(1) {
my ($self, $c, $id) = @_;
my $build = getBuild($c, $id);
return error($c, "Build with ID $id doesn't exist.") if !defined $build;
$c->stash->{curProject} = $build->project;
$c->stash->{template} = 'build.tt';
$c->stash->{build} = $build;
$c->stash->{id} = $id;
$c->stash->{build} = getBuild($c, $id);
if (!defined $c->stash->{build}) {
error($c, "Build with ID $id doesn't exist.");
$c->response->status(404);
return;
}
$c->stash->{curProject} = $c->stash->{build}->project;
}
sub view_build : Chained('build') PathPart('') Args(0) {
my ($self, $c) = @_;
my $build = $c->stash->{build};
$c->stash->{template} = 'build.tt';
$c->stash->{curTime} = time;
$c->stash->{available} = isValidPath $build->outpath;
if (!$build->finished && $build->schedulingInfo->busy) {
@ -598,35 +606,13 @@ sub build :Local {
}
sub log :Local {
my ($self, $c, $id) = @_;
sub view_nixlog : Chained('build') PathPart('nixlog') Args(1) {
my ($self, $c, $stepnr) = @_;
my $build = getBuild($c, $id);
return error($c, "Build $id doesn't exist.") if !defined $build;
return error($c, "Build $id didn't produce a log.") if !defined $build->resultInfo->logfile;
my $step = $c->stash->{build}->buildsteps->find({stepnr => $stepnr});
return error($c, "Build doesn't have a build step $stepnr.") if !defined $step;
$c->stash->{template} = 'log.tt';
$c->stash->{build} = $build;
# !!! should be done in the view (as a TT plugin).
$c->stash->{logtext} = loadLog($c, $build->resultInfo->logfile);
}
sub nixlog :Local {
my ($self, $c, $id, $stepnr) = @_;
my $build = getBuild($c, $id);
return error($c, "Build with ID $id doesn't exist.") if !defined $build;
my $step = $build->buildsteps->find({stepnr => $stepnr});
return error($c, "Build $id doesn't have a build step $stepnr.") if !defined $step;
return error($c, "Build step $stepnr of build $id does not have a log file.") if $step->logfile eq "";
$c->stash->{template} = 'log.tt';
$c->stash->{build} = $build;
$c->stash->{step} = $step;
# !!! should be done in the view (as a TT plugin).
@ -634,6 +620,18 @@ sub nixlog :Local {
}
sub view_log : Chained('build') PathPart('log') Args(0) {
my ($self, $c) = @_;
return error($c, "Build didn't produce a log.") if !defined $c->stash->{build}->resultInfo->logfile;
$c->stash->{template} = 'log.tt';
# !!! should be done in the view (as a TT plugin).
$c->stash->{logtext} = loadLog($c, $c->stash->{build}->resultInfo->logfile);
}
sub loadLog {
my ($c, $path) = @_;
@ -648,14 +646,11 @@ sub loadLog {
}
sub download :Local {
my ($self, $c, $id, $productnr, $filename, @path) = @_;
sub download : Chained('build') PathPart('download') {
my ($self, $c, $productnr, $filename, @path) = @_;
my $build = getBuild($c, $id);
return error($c, "Build with ID $id doesn't exist.") if !defined $build;
my $product = $build->buildproducts->find({productnr => $productnr});
return error($c, "Build $id doesn't have a product $productnr.") if !defined $product;
my $product = $c->stash->{build}->buildproducts->find({productnr => $productnr});
return error($c, "Build doesn't have a product $productnr.") if !defined $product;
return error($c, "Product " . $product->path . " has disappeared.") unless -e $product->path;
@ -748,7 +743,15 @@ sub nar :Local {
}
sub end : ActionClass('RenderView') {}
sub end : ActionClass('RenderView') {
my ($self, $c) = @_;
if (scalar @{$c->error}) {
$c->stash->{template} = 'error.tt';
$c->stash->{errors} = $c->error;
$c->clear_errors;
}
}
1;

View file

@ -121,7 +121,7 @@
<tr>
<th>Logfile:</th>
<td>
<a href="[% c.uri_for('/log' build.id) %]"><strong>Available</strong></a>
<a href="[% c.uri_for('build' build.id 'log') %]"><strong>Available</strong></a>
</td>
</tr>
[% END %]
@ -178,8 +178,9 @@
</thead>
<tbody>
[% FOREACH step IN build.buildsteps -%]
[% log = c.uri_for('build' build.id 'nixlog' step.stepnr) %]
<tr class="[% IF step.logfile %]clickable[% END %]"
[% IF step.logfile %] onclick="window.location = '[% c.uri_for('/nixlog' build.id step.stepnr) %]'" [% END %]>
[% IF step.logfile %] onclick="window.location = '[% log %]'" [% END %]>
<td>[% step.stepnr %]</td>
<td>
[% IF step.type == 0 %]
@ -212,7 +213,7 @@
<span class="error">Failed: [% HTML.escape(step.errormsg) %]</span>
[% END %]
[% IF step.logfile %]
(<a href="[% c.uri_for('/nixlog' build.id step.stepnr) %]">log</a>)
(<a href="[% log %]">log</a>)
[% END %]
</td>
</tr>

View file

@ -3,6 +3,6 @@
<h1>Error</h1>
<p>I'm very sorry, but an error occurred: <span class="error-msg">[% HTML.escape(error) %]</span></p>
<p>I'm very sorry, but an error occurred: <span class="error-msg">[% FOREACH error IN errors %] [% HTML.escape(error) %] [% END %]</span></p>
[% END %]

View file

@ -5,13 +5,16 @@
<ul class="productList">
[% FOREACH product IN build.buildproducts -%]
[% uri = c.uri_for('build' build.id 'download' product.productnr product.name) %]
[% SWITCH product.type %]
[% CASE "nix-build" %]
<li class="product">
<a href="[% c.uri_for('/nixpkg' build.id) %]">
[% uri = c.uri_for('nixpkg' build.id) %]
<a href="[% uri %]">
<img src="/static/images/nix-build.png" alt="Source" />
One-click install of Nix package <tt>[% build.nixname %]</tt>
</a>
@ -25,7 +28,7 @@
browser. Alternatively, you can install it from the
command-line:
<pre>$ nix-install-package --non-interactive --url [% c.uri_for('/nixpkg' build.id) %]</pre>
<pre>$ nix-install-package --non-interactive --url [% uri %]</pre>
</p>
@ -76,7 +79,7 @@
[% CASE "file" %]
<li class="product">
<a href="[% c.uri_for('/download' build.id product.productnr product.name) %]">
<a href="[% uri %]">
[% SWITCH product.subtype %]
[% CASE "source-dist" %]
<img src="/static/images/source-dist.png" alt="Source" /> Source distribution <tt>[% product.name %]</tt>
@ -96,8 +99,8 @@
<tr>
<th>URL:</th>
<td>
<a href="[% c.uri_for('/download' build.id product.productnr product.name) %]">
<tt>[% c.uri_for('/download' build.id product.productnr product.name) %]</tt>
<a href="[% uri %]">
<tt>[% uri %]</tt>
</a>
</td>
</tr>
@ -112,7 +115,7 @@
[% CASE "report" %]
<li class="product">
<a href="[% c.uri_for('/download' build.id product.productnr product.name) %]">
<a href="[% uri %]">
<img src="/static/images/report.png" alt="Report" />
[% SWITCH product.subtype %]
[% CASE "coverage" %]
@ -126,7 +129,7 @@
[% CASE "doc" %]
<li class="product">
<a href="[% c.uri_for('/download' build.id product.productnr product.name) %]">
<a href="[% uri %]">
<img src="/static/images/document.png" alt="Document" />
[% SWITCH product.subtype %]
[% CASE "readme" %]