* More renaming.

This commit is contained in:
Eelco Dolstra 2009-10-20 12:35:01 +00:00
parent 321027b262
commit 2cf42489e2
3 changed files with 38 additions and 33 deletions

View file

@ -95,8 +95,8 @@ sub view_view : Chained('view') PathPart('') Args(0) {
my $page = int($c->req->param('page')) || 1;
my @results = ();
push @results, getRelease($_, $c->stash->{jobs}) foreach
getPrimaryBuildsForReleaseSet($c->stash->{project}, $c->stash->{primaryJob}, $page, $resultsPerPage);
push @results, getViewResult($_, $c->stash->{jobs}) foreach
getPrimaryBuildsForView($c->stash->{project}, $c->stash->{primaryJob}, $page, $resultsPerPage);
$c->stash->{baseUri} = $c->uri_for($self->action_for("view_view"), $c->req->captures);
$c->stash->{results} = [@results];
@ -138,7 +138,7 @@ sub latest : Chained('view') PathPart('latest') {
# Redirect to the latest result in the view in which every build
# is successful.
my $latest = getLatestSuccessfulRelease(
my $latest = getLatestSuccessfulViewResult(
$c->stash->{project}, $c->stash->{primaryJob}, $c->stash->{jobs});
error($c, "This view set has no successful results yet.") if !defined $latest;
$c->res->redirect($c->uri_for($self->action_for("view_view"), $c->req->captures, $latest->id, @args));
@ -158,7 +158,7 @@ sub result : Chained('view') PathPart('') {
, '+as' => ["releasename", "buildstatus"] })
or error($c, "Build $id doesn't exist.");
$c->stash->{result} = getRelease($primaryBuild, $c->stash->{jobs});
$c->stash->{result} = getViewResult($primaryBuild, $c->stash->{jobs});
# Provide a redirect to the specified job of this view result.
# !!! This isn't uniquely defined if there are multiple jobs with

View file

@ -10,9 +10,9 @@ our @EXPORT = qw(
isValidPath queryPathInfo
getHydraPath getHydraDBPath openHydraDB txn_do
registerRoot getGCRootsDir gcRootFor
getPrimaryBuildsForReleaseSet
getPrimaryBuildsForView
getPrimaryBuildTotal
getRelease getLatestSuccessfulRelease );
getViewResult getLatestSuccessfulViewResult );
sub isValidPath {
@ -135,7 +135,7 @@ sub attrsToSQL {
my $query = "1 = 1";
foreach my $attr (@attrs) {
$attr =~ /^([\w-]+)=([\w-]*)$/ or die "invalid attribute in release set: $attr";
$attr =~ /^([\w-]+)=([\w-]*)$/ or die "invalid attribute in view: $attr";
my $name = $1;
my $value = $2;
# !!! Yes, this is horribly injection-prone... (though
@ -149,23 +149,25 @@ sub attrsToSQL {
}
sub allPrimaryBuilds {
my ($project, $primaryJob) = @_;
my $allPrimaryBuilds = $project->builds->search(
{ jobset => $primaryJob->get_column('jobset'), job => $primaryJob->get_column('job'), finished => 1 },
{ join => 'resultInfo', order_by => "timestamp DESC"
, '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"]
, '+as' => ["releasename", "buildstatus"]
, where => \ attrsToSQL($primaryJob->attrs, "me.id")
});
return $allPrimaryBuilds;
my ($project, $primaryJob) = @_;
my $allPrimaryBuilds = $project->builds->search(
{ jobset => $primaryJob->get_column('jobset'), job => $primaryJob->get_column('job'), finished => 1 },
{ join => 'resultInfo', order_by => "timestamp DESC"
, '+select' => ["resultInfo.releasename", "resultInfo.buildstatus"]
, '+as' => ["releasename", "buildstatus"]
, where => \ attrsToSQL($primaryJob->attrs, "me.id")
});
return $allPrimaryBuilds;
}
sub getPrimaryBuildTotal {
my ($project, $primaryJob) = @_;
return scalar(allPrimaryBuilds($project, $primaryJob)) ;
return scalar(allPrimaryBuilds($project, $primaryJob));
}
sub getPrimaryBuildsForReleaseSet {
sub getPrimaryBuildsForView {
my ($project, $primaryJob, $page, $resultsPerPage) = @_;
$page = (defined $page ? int($page) : 1) || 1;
$resultsPerPage = (defined $resultsPerPage ? int($resultsPerPage) : 20) || 20;
@ -178,6 +180,7 @@ sub getPrimaryBuildsForReleaseSet {
return @primaryBuilds;
}
sub findLastJobForBuilds {
my ($builds, $job) = @_;
my $thisBuild;
@ -198,6 +201,7 @@ sub findLastJobForBuilds {
}
sub findLastJobForPrimaryBuild {
my ($primaryBuild, $job) = @_;
my $thisBuild;
@ -219,14 +223,15 @@ sub findLastJobForPrimaryBuild {
return $thisBuild;
}
sub getRelease {
sub getViewResult {
my ($primaryBuild, $jobs) = @_;
my @jobs = ();
my $status = 0; # = okay
# The timestamp of the release is the highest timestamp of all
# The timestamp of the view result is the highest timestamp of all
# constitutent builds.
my $timestamp = 0;
@ -261,11 +266,11 @@ sub getRelease {
}
sub getLatestSuccessfulRelease {
sub getLatestSuccessfulViewResult {
my ($project, $primaryJob, $jobs) = @_;
my $latest;
foreach my $build (getPrimaryBuildsForReleaseSet($project, $primaryJob)) {
return $build if getRelease($build, $jobs)->{status} == 0;
foreach my $build (getPrimaryBuildsForView($project, $primaryJob)) {
return $build if getViewResult($build, $jobs)->{status} == 0;
}
return undef;

View file

@ -57,20 +57,20 @@ foreach my $project ($db->resultset('Projects')->all) {
keepBuild $_ foreach @recentBuilds;
}
# Go over all releases in this project.
# Go over all views in this project.
foreach my $releaseSet ($project->releasesets->all) {
print STDERR "*** looking for builds to keep in release set ", $project->name, ":", $releaseSet->name, "\n";
foreach my $view ($project->views->all) {
print STDERR "*** looking for builds to keep in view ", $project->name, ":", $view->name, "\n";
(my $primaryJob) = $releaseSet->releasesetjobs->search({isprimary => 1});
my $jobs = [$releaseSet->releasesetjobs->all];
(my $primaryJob) = $view->viewjobs->search({isprimary => 1});
my $jobs = [$view->viewjobs->all];
# Keep all builds belonging to the most recent successful release.
my $latest = getLatestSuccessfulRelease($project, $primaryJob, $jobs);
# Keep all builds belonging to the most recent successful view result.
my $latest = getLatestSuccessfulViewResult($project, $primaryJob, $jobs);
if (defined $latest) {
print STDERR "keeping latest successful release ", $latest->id, " (", $latest->get_column('releasename'), ")\n";
my $release = getRelease($latest, $jobs);
keepBuild $_->{build} foreach @{$release->{jobs}};
print STDERR "keeping latest successful view result ", $latest->id, " (", $latest->get_column('releasename'), ")\n";
my $result = getViewResult($latest, $jobs);
keepBuild $_->{build} foreach @{$result->{jobs}};
}
}