* Provide some redirects to build products by type so that we can for

example link to the latest tarball through a URI like:

    http://server/job/patchelf/trunk/tarball/latest/download-by-type/file/source-dist
This commit is contained in:
Eelco Dolstra 2009-04-08 08:09:39 +00:00
parent f9572e4d1e
commit 26ff5f1ff0
3 changed files with 43 additions and 8 deletions

View file

@ -61,21 +61,21 @@ sub nix : Chained('get_builds') PathPart('channel') CaptureArgs(1) {
# Redirect to the latest successful build.
sub latest : Chained('get_builds') PathPart('latest') {
my ($self, $c) = @_;
my ($self, $c, @rest) = @_;
my ($latest) = joinWithResultInfo($c, $c->stash->{allBuilds})
->search({finished => 1, buildstatus => 0}, {order_by => ["timestamp DESC"]});
notFound "There is no successful build to redirect to." unless defined $latest;
$c->res->redirect($c->uri_for($c->controller('Build')->action_for("view_build"), [$latest->id]));
$c->res->redirect($c->uri_for($c->controller('Build')->action_for("view_build"), [$latest->id], @rest));
}
# Redirect to the latest successful build for a specific platform.
sub latest_for : Chained('get_builds') PathPart('latest-for') {
my ($self, $c, $system) = @_;
my ($self, $c, $system, @rest) = @_;
notFound($c, "You need to specify a platform type in the URL.") unless defined $system;
@ -84,8 +84,7 @@ sub latest_for : Chained('get_builds') PathPart('latest-for') {
notFound($c, "There is no successful build for platform `$system' to redirect to.") unless defined $latest;
$c->res->redirect($c->uri_for($c->controller('Build')->action_for("view_build"), [$latest->id]));
$c->res->redirect($c->uri_for($c->controller('Build')->action_for("view_build"), [$latest->id], @rest));
}

View file

@ -90,6 +90,15 @@ sub showLog {
}
sub defaultUriForProduct {
my ($self, $c, $product, @path) = @_;
my $x = $product->productnr
. ($product->name ? "/" . $product->name : "")
. ($product->defaultpath ? "/" . $product->defaultpath : "");
return $c->uri_for($self->action_for("download"), $c->req->captures, $x, @path);
}
sub download : Chained('build') PathPart {
my ($self, $c, $productnr, @path) = @_;
@ -98,6 +107,9 @@ sub download : Chained('build') PathPart {
notFound($c, "Product " . $product->path . " has disappeared.") unless -e $product->path;
return $c->res->redirect(defaultUriForProduct($self, $c, $product, @path))
if scalar @path == 0 && ($product->name || $product->defaultpath);
# If the product has a name, then the first path element can be
# ignored (it's the name included in the URL for informational purposes).
shift @path if $product->name;
@ -125,6 +137,24 @@ sub download : Chained('build') PathPart {
}
# Redirect to a download with the given type. Useful when you want to
# link to some build product of the latest build (i.e. in conjunction
# with the .../latest redirect).
sub download_by_type : Chained('build') PathPart('download-by-type') {
my ($self, $c, $type, $subtype, @path) = @_;
notFound($c, "You need to specify a type and a subtype in the URI.")
unless defined $type && defined $subtype;
(my $product) = $c->stash->{build}->buildproducts->search(
{type => $type, subtype => $subtype});
notFound($c, "Build doesn't have a build product with type $type/$subtype.")
if !defined $product;
$c->res->redirect(defaultUriForProduct($self, $c, $product, @path));
}
sub contents : Chained('build') PathPart Args(1) {
my ($self, $c, $productnr) = @_;

View file

@ -103,10 +103,16 @@
<table>
<tr>
<th>URL:</th>
<td><a href="[% uri %]"><tt>[% uri %]</tt></a></td>
</tr>
<tr>
<th>Links to latest:</th>
<td>
<a href="[% uri %]">
<tt>[% uri %]</tt>
</a>
[% uri2 = "${c.uri_for('/job' build.project.name build.jobset.name build.job.name 'latest' 'download-by-type' product.type product.subtype)}" %]
<a href="[% uri2 %]"><tt>[% uri2 %]</tt></a>
<br />
[% uri2 = "${c.uri_for('/job' build.project.name build.jobset.name build.job.name 'latest' 'download' product.productnr)}" %]
<a href="[% uri2 %]"><tt>[% uri2 %]</tt></a>
</td>
</tr>
<tr><th>File size:</th><td>[% product.filesize %] bytes ([% mibs(product.filesize / (1024 * 1024)) %] MiB)</td></tr>