* More release -> view.

This commit is contained in:
Eelco Dolstra 2009-10-20 12:26:39 +00:00
parent 8f9417f822
commit 321027b262
7 changed files with 121 additions and 71 deletions

View file

@ -180,4 +180,34 @@ sub get_builds : Chained('project') PathPart('') CaptureArgs(0) {
}
sub create_view_submit : Chained('project') PathPart('create-view/submit') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
my $viewName = $c->request->params->{name};
my $view;
txn_do($c->model('DB')->schema, sub {
# Note: $viewName is validated in updateView, which will abort
# the transaction if the name isn't valid.
$view = $c->stash->{project}->views->create({name => $viewName});
Hydra::Controller::View::updateView($c, $view);
});
$c->res->redirect($c->uri_for($c->controller('View')->action_for('view_view'),
[$c->stash->{project}->name, $view->name]));
}
sub create_view : Chained('project') PathPart('create-view') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
$c->stash->{template} = 'edit-view.tt';
$c->stash->{create} = 1;
}
1;

View file

@ -30,18 +30,18 @@ sub getView {
}
sub updateReleaseSet {
my ($c, $releaseSet) = @_;
sub updateView {
my ($c, $view) = @_;
my $releaseSetName = trim $c->request->params->{name};
error($c, "Invalid release set name: $releaseSetName")
unless $releaseSetName =~ /^[[:alpha:]][\w\-]*$/;
my $viewName = trim $c->request->params->{name};
error($c, "Invalid view name: $viewName")
unless $viewName =~ /^[[:alpha:]][\w\-]*$/;
$releaseSet->update(
{ name => $releaseSetName
$view->update(
{ name => $viewName
, description => trim $c->request->params->{description} });
$releaseSet->releasesetjobs->delete_all;
$view->viewjobs->delete_all;
foreach my $param (keys %{$c->request->params}) {
next unless $param =~ /^job-(\d+)-name$/;
@ -56,13 +56,13 @@ sub updateReleaseSet {
my $jobName = $2;
error($c, "Jobset `$jobsetName' doesn't exist.")
unless $releaseSet->project->jobsets->find({name => $jobsetName});
unless $view->project->jobsets->find({name => $jobsetName});
# !!! We could check whether the job exists, but that would
# require the scheduler to have seen the job, which may not be
# the case.
$releaseSet->releasesetjobs->create(
$view->viewjobs->create(
{ jobset => $jobsetName
, job => $jobName
, description => $description
@ -72,7 +72,7 @@ sub updateReleaseSet {
}
error($c, "There must be one primary job.")
if $releaseSet->releasesetjobs->search({isprimary => 1})->count != 1;
if $view->viewjobs->search({isprimary => 1})->count != 1;
}
@ -98,7 +98,7 @@ sub view_view : Chained('view') PathPart('') Args(0) {
push @results, getRelease($_, $c->stash->{jobs}) foreach
getPrimaryBuildsForReleaseSet($c->stash->{project}, $c->stash->{primaryJob}, $page, $resultsPerPage);
$c->stash->{baseUri} = $c->uri_for($self->action_for("view"), $c->stash->{project}->name, $c->stash->{view}->name);
$c->stash->{baseUri} = $c->uri_for($self->action_for("view_view"), $c->req->captures);
$c->stash->{results} = [@results];
$c->stash->{page} = $page;
$c->stash->{totalResults} = getPrimaryBuildTotal($c->stash->{project}, $c->stash->{primaryJob});
@ -113,6 +113,26 @@ sub edit : Chained('view') PathPart('edit') Args(0) {
}
sub submit : Chained('view') PathPart('submit') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
txn_do($c->model('DB')->schema, sub {
updateView($c, $c->stash->{view});
});
$c->res->redirect($c->uri_for($self->action_for("view_view"), $c->req->captures));
}
sub delete : Chained('view') PathPart('delete') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
txn_do($c->model('DB')->schema, sub {
$c->stash->{view}->delete;
});
$c->res->redirect($c->uri_for($c->controller('Project')->action_for('view'), [$c->stash->{project}->name]));
}
sub latest : Chained('view') PathPart('latest') {
my ($self, $c, @args) = @_;
@ -121,14 +141,14 @@ sub latest : Chained('view') PathPart('latest') {
my $latest = getLatestSuccessfulRelease(
$c->stash->{project}, $c->stash->{primaryJob}, $c->stash->{jobs});
error($c, "This view set has no successful results yet.") if !defined $latest;
return $c->res->redirect($c->uri_for("/view", $c->stash->{project}->name, $c->stash->{view}->name, $latest->id, @args));
$c->res->redirect($c->uri_for($self->action_for("view_view"), $c->req->captures, $latest->id, @args));
}
sub result : Chained('view') PathPart('') {
my ($self, $c, $id, @args) = @_;
$c->stash->{template} = 'release.tt';
$c->stash->{template} = 'view-result.tt';
# Note: we don't actually check whether $id is a primary build,
# but who cares?
@ -138,18 +158,18 @@ sub result : Chained('view') PathPart('') {
, '+as' => ["releasename", "buildstatus"] })
or error($c, "Build $id doesn't exist.");
$c->stash->{release} = getRelease($primaryBuild, $c->stash->{jobs});
$c->stash->{result} = getRelease($primaryBuild, $c->stash->{jobs});
# Provide a redirect to the specified job of this release. !!!
# This isn't uniquely defined if there are multiple jobs with the
# same name (e.g. builds for different platforms). However, this
# mechanism is primarily to allow linking to resources of which
# there is only one build, such as the manual of the latest
# release.
# Provide a redirect to the specified job of this view result.
# !!! This isn't uniquely defined if there are multiple jobs with
# the same name (e.g. builds for different platforms). However,
# this mechanism is primarily to allow linking to resources of
# which there is only one build, such as the manual of the latest
# view result.
if (scalar @args != 0) {
my $jobName = shift @args;
(my $build, my @others) = grep { $_->{job}->job eq $jobName } @{$c->stash->{release}->{jobs}};
notFound($c, "Release doesn't have a job named `$jobName'")
(my $build, my @others) = grep { $_->{job}->job eq $jobName } @{$c->stash->{result}->{jobs}};
notFound($c, "View doesn't have a job named `$jobName'")
unless defined $build;
error($c, "Job `$jobName' isn't unique.") if @others;
return $c->res->redirect($c->uri_for($c->controller('Build')->action_for('view_build'),

View file

@ -159,7 +159,7 @@
[% END %]
[% BLOCK renderReleaseJobName -%]
[% BLOCK renderViewJobName -%]
[% IF job.description; HTML.escape(job.description); ELSE %]<tt>[% job.job %]</tt> ([% job.attrs %])[% END -%]
[% END -%]

View file

@ -21,7 +21,7 @@
[% END %]
<form action="[% IF create %][% c.uri_for('/create-view' project.name 'submit') %][% ELSE %][% c.uri_for('/view' project.name view.name 'submit') %][% END %]" method="post">
<form action="[% IF create %][% c.uri_for('/project' project.name 'create-view/submit') %][% ELSE %][% c.uri_for('/view' project.name view.name 'submit') %][% END %]" method="post">
<table class="layoutTable">
<tr>

View file

@ -1,45 +0,0 @@
[% releaseName = (release.releasename || "(No name)") -%]
[% WRAPPER layout.tt title="Release $releaseName" %]
[% PROCESS common.tt %]
[% PROCESS "product-list.tt" %]
[% USE HTML %]
<h1>Release <tt>[% releaseName %]</tt></h1>
<p><em>Released on [% INCLUDE renderDateTime timestamp = release.timestamp %].</em></p>
[% IF release.status == 1 %]
<p class="error">This is a failed release. One of its jobs has failed. See below for details.</p>
[% ELSIF release.status == 2 %]
<p class="error">This is an incomplete release. One of its jobs has not been built (yet). See below for details.</p>
[% END %]
[% FOREACH j IN release.jobs %]
<h2>
[% IF j.build %]<a href="[% c.uri_for('/build' j.build.id) %]">[% END %]
[% INCLUDE renderReleaseJobName job=j.job %]
[% IF j.build %]</a>[% END %]
</h2>
[% IF j.build %]
[% IF j.build.resultInfo.buildstatus == 0 %]
[% INCLUDE renderProductList build=j.build latestRoot=['/release' project.name releaseSet.name 'latest' j.job.job] %]
[% ELSE %]
<p class="error">Build failed</p>
[% END %]
[% ELSE %]
<p class="error">Build not (yet) performed.</p>
[% END %]
[% END %]
[% END %]

45
src/root/view-result.tt Normal file
View file

@ -0,0 +1,45 @@
[% releaseName = (result.releasename || "(No name)") -%]
[% WRAPPER layout.tt title="View $releaseName" %]
[% PROCESS common.tt %]
[% PROCESS "product-list.tt" %]
[% USE HTML %]
<h1>View <tt>[% view.project.name %]:[% view.name %]</tt> result [% result.id %][% IF result.releasename %] (<tt>[% result.releasename %]</tt>)[% END %]</h1>
<p><em>Finished building on [% INCLUDE renderDateTime timestamp = result.timestamp %].</em></p>
[% IF result.status == 1 %]
<p class="error">Note: One or more of the jobs in the view did not build correctly. See below for details.</p>
[% ELSIF result.status == 2 %]
<p class="error">Note: One or more of the jobs in the view have not been built (yet). See below for details.</p>
[% END %]
[% FOREACH j IN result.jobs %]
<h2>
[% IF j.build %]<a href="[% c.uri_for('/build' j.build.id) %]">[% END %]
[% INCLUDE renderViewJobName job=j.job %]
[% IF j.build %]</a>[% END %]
</h2>
[% IF j.build %]
[% IF j.build.resultInfo.buildstatus == 0 %]
[% INCLUDE renderProductList build=j.build latestRoot=['/view' project.name view.name 'latest' j.job.job] %]
[% ELSE %]
<p class="error">Build failed</p>
[% END %]
[% ELSE %]
<p class="error">Build not (yet) performed.</p>
[% END %]
[% END %]
[% END %]

View file

@ -19,7 +19,7 @@
<th>Name</th>
<th>Date</th>
[% FOREACH j IN jobs %]
<th class="releaseSetJobName">[% INCLUDE renderReleaseJobName job=j %]</th>
<th class="releaseSetJobName">[% INCLUDE renderViewJobName job=j %]</th>
[% END %]
</tr>
</thead>