* Allow a view result to be saved as a release.

This commit is contained in:
Eelco Dolstra 2009-10-27 15:31:26 +00:00
parent 9aa70716ad
commit 3e5e49debd
4 changed files with 43 additions and 4 deletions

View file

@ -159,7 +159,38 @@ sub result : Chained('view') PathPart('') {
, '+as' => ["releasename", "buildstatus"] })
or error($c, "Build $id doesn't exist.");
$c->stash->{result} = getViewResult($primaryBuild, $c->stash->{jobs});
my $result = getViewResult($primaryBuild, $c->stash->{jobs});
$c->stash->{result} = $result;
if (scalar @args == 1 && $args[0] eq "release") {
requireProjectOwner($c, $c->stash->{project});
error($c, "The primary build of this view result did not provide a release name.")
unless $result->{releasename};
error($c, "A release named `" . $result->{releasename} . "' already exists.")
if $c->stash->{project}->releases->find({name => $result->{releasename}});
my $release;
txn_do($c->model('DB')->schema, sub {
$release = $c->stash->{project}->releases->create(
{ name => $result->{releasename}
, timestamp => time
});
foreach my $job (@{$result->{jobs}}) {
$release->releasemembers->create(
{ build => $job->{build}->id
, description => $job->{job}->description
});
}
});
$c->res->redirect($c->uri_for($c->controller('Release')->action_for('view'),
[$c->stash->{project}->name, $release->name]));
}
# Provide a redirect to the specified job of this view result.
# !!! This isn't uniquely defined if there are multiple jobs with
@ -167,9 +198,9 @@ sub result : Chained('view') PathPart('') {
# 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) {
elsif (scalar @args != 0) {
my $jobName = shift @args;
(my $build, my @others) = grep { $_->{job}->job eq $jobName } @{$c->stash->{result}->{jobs}};
(my $build, my @others) = grep { $_->{job}->job eq $jobName } @{$result->{jobs}};
notFound($c, "View doesn't have a job named `$jobName'")
unless defined $build;
error($c, "Job `$jobName' isn't unique.") if @others;

View file

@ -111,6 +111,7 @@
<th>URL:</th>
<td><a href="[% uri %]"><tt>[% uri %]</tt></a></td>
</tr>
[% IF latestRoot %]
<tr>
<th>Links to latest:</th>
<td>
@ -126,6 +127,7 @@
[% END %]
</td>
</tr>
[% END %]
<tr><th>File size:</th><td>[% product.filesize %] bytes ([% mibs(product.filesize / (1024 * 1024)) %] MiB)</td></tr>
<tr><th>SHA-1 hash:</th><td><tt>[% product.sha1hash %]</tt></td></tr>
<tr><th>SHA-256 hash:</th><td><tt>[% product.sha256hash %]</tt></td></tr>

View file

@ -23,7 +23,7 @@ release.timestamp %].</em></p>
</a>
</h2>
[% INCLUDE renderProductList build=m.build latestRoot=['/view!!!' project.name view.name 'latest' j.job.job] %]
[% INCLUDE renderProductList build=m.build %]
[% END %]

View file

@ -42,4 +42,10 @@
[% END %]
[% IF c.user_exists %]
<p>
[<a href="[% c.uri_for('/view' project.name view.name result.id 'release') %]">Release</a>]
</p>
[% END %]
[% END %]