From 5e207cdbb28baee2337b13fd989d37405128c215 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 15 Dec 2008 13:12:51 +0000 Subject: [PATCH] * Provide a redirect to the latest successful release in a release set (e.g. http://localhost:3000/release/patchelf/unstable/latest). --- src/Hydra/lib/Hydra/Controller/Root.pm | 36 ++++++++++++++++++++------ src/Hydra/root/releases.tt | 5 +++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Hydra/lib/Hydra/Controller/Root.pm b/src/Hydra/lib/Hydra/Controller/Root.pm index 1a57db52..e12e7921 100644 --- a/src/Hydra/lib/Hydra/Controller/Root.pm +++ b/src/Hydra/lib/Hydra/Controller/Root.pm @@ -307,6 +307,18 @@ sub updateReleaseSet { die "There must be one primary job." if $releaseSet->releasesetjobs->search({isprimary => 1})->count != 1; } + +sub getPrimaryBuildsForReleaseSet { + my ($project, $primaryJob) = @_; + my @primaryBuilds = $project->builds->search( + { attrname => $primaryJob->job, finished => 1 }, + { join => 'resultInfo', order_by => "timestamp DESC" + , '+select' => ["resultInfo.releasename"], '+as' => ["releasename"] + , where => \ attrsToSQL($primaryJob->attrs, "me.id") + }); + return @primaryBuilds; +} + sub releases :Local { my ($self, $c, $projectName, $releaseSetName, $subcommand) = @_; @@ -343,16 +355,9 @@ sub releases :Local { } $c->stash->{template} = 'releases.tt'; - my @primaryBuilds = $project->builds->search( - { attrname => $primaryJob->job, finished => 1 }, - { join => 'resultInfo', order_by => "timestamp DESC" - , '+select' => ["resultInfo.releasename"], '+as' => ["releasename"] - , where => \ attrsToSQL($primaryJob->attrs, "me.id") - }); my @releases = (); - push @releases, getRelease($c, $_) foreach @primaryBuilds; - + push @releases, getRelease($c, $_) foreach getPrimaryBuildsForReleaseSet($project, $primaryJob); $c->stash->{releases} = [@releases]; } @@ -397,6 +402,21 @@ sub release :Local { my ($project, $releaseSet, $primaryJob) = getReleaseSet($c, $projectName, $releaseSetName); + if ($releaseId eq "latest") { + # Redirect to the latest successful release. + my $latest; + foreach my $release (getPrimaryBuildsForReleaseSet($project, $primaryJob)) { + if (getRelease($c, $release)->{status} == 0) { + $latest = $release; + last; + } + } + + return error($c, "This release set has no successful releases yet.") if !defined $latest; + + return $c->res->redirect($c->uri_for("/release", $projectName, $releaseSetName, $latest->id)); + } + # Note: we don't actually check whether $releaseId is a primary # build, but who cares? my $primaryBuild = $project->builds->find($releaseId, diff --git a/src/Hydra/root/releases.tt b/src/Hydra/root/releases.tt index a0b88c4b..c0eeb62e 100644 --- a/src/Hydra/root/releases.tt +++ b/src/Hydra/root/releases.tt @@ -4,7 +4,10 @@

Release Set [% releaseSet.project.name %]:[% releaseSet.name %]

-

[Edit]

+

+[Edit] +[Latest] +