diff --git a/src/lib/Hydra/Base/Controller/ListBuilds.pm b/src/lib/Hydra/Base/Controller/ListBuilds.pm index 2b1352e1..22d46e70 100644 --- a/src/lib/Hydra/Base/Controller/ListBuilds.pm +++ b/src/lib/Hydra/Base/Controller/ListBuilds.pm @@ -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)); } diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index 4751eeff..d324ed2c 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -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) = @_; diff --git a/src/root/product-list.tt b/src/root/product-list.tt index 6b90c54a..660122ad 100644 --- a/src/root/product-list.tt +++ b/src/root/product-list.tt @@ -103,10 +103,16 @@ + + + +
URL:[% uri %]
Links to latest: - - [% uri %] - + [% uri2 = "${c.uri_for('/job' build.project.name build.jobset.name build.job.name 'latest' 'download-by-type' product.type product.subtype)}" %] + [% uri2 %] +
+ [% uri2 = "${c.uri_for('/job' build.project.name build.jobset.name build.job.name 'latest' 'download' product.productnr)}" %] + [% uri2 %]
File size:[% product.filesize %] bytes ([% mibs(product.filesize / (1024 * 1024)) %] MiB)