* Creating releases.

This commit is contained in:
Eelco Dolstra 2009-10-23 09:58:23 +00:00
parent 929cbe7b7c
commit 851a4dff4d
6 changed files with 205 additions and 3 deletions

View file

@ -217,9 +217,34 @@ sub releases : Chained('project') PathPart('releases') Args(0) {
}
sub create_release : Chained('project') PathPart('releases/create') {
sub create_release : Chained('project') PathPart('create-release') Args(0) {
my ($self, $c) = @_;
$c->stash->{template} = 'create-release.tt';
requireProjectOwner($c, $c->stash->{project});
$c->stash->{template} = 'edit-release.tt';
$c->stash->{create} = 1;
}
sub create_release_submit : Chained('project') PathPart('create-release/submit') Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
my $releaseName = $c->request->params->{name};
my $release;
txn_do($c->model('DB')->schema, sub {
# Note: $releaseName is validated in updateRelease, which will
# abort the transaction if the name isn't valid.
$release = $c->stash->{project}->releases->create(
{ name => $releaseName
, timestamp => time
});
Hydra::Controller::Release::updateRelease($c, $release);
});
$c->res->redirect($c->uri_for($c->controller('Release')->action_for('view'),
[$c->stash->{project}->name, $release->name]));
}

View file

@ -0,0 +1,37 @@
package Hydra::Controller::Release;
use strict;
use warnings;
use base 'Catalyst::Controller';
use Hydra::Helper::Nix;
use Hydra::Helper::CatalystUtils;
sub release : Chained('/') PathPart('release') CaptureArgs(2) {
my ($self, $c, $projectName, $releaseName) = @_;
#$c->stash->{project} = $project;
#$c->stash->{release} = $view;
}
sub view : Chained('release') PathPart('') Args(0) {
my ($self, $c) = @_;
$c->stash->{template} = 'release.tt';
}
sub updateRelease {
my ($c, $release) = @_;
my $releaseName = trim $c->request->params->{name};
error($c, "Invalid release name: $releaseName")
unless $releaseName =~ /^[[:alpha:]][\w\-]*$/;
$release->update(
{ name => $releaseName
, description => trim $c->request->params->{description}
});
}
1;

View file

@ -0,0 +1,58 @@
package Hydra::Schema::ReleaseMembers;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("ReleaseMembers");
__PACKAGE__->add_columns(
"project",
{
data_type => "text",
default_value => undef,
is_foreign_key => 1,
is_nullable => 0,
size => undef,
},
"release_",
{
data_type => "text",
default_value => undef,
is_foreign_key => 1,
is_nullable => 0,
size => undef,
},
"build",
{
data_type => "integer",
default_value => undef,
is_foreign_key => 1,
is_nullable => 0,
size => undef,
},
"description",
{
data_type => "text",
default_value => undef,
is_nullable => 1,
size => undef,
},
);
__PACKAGE__->set_primary_key("project", "release_", "build");
__PACKAGE__->belongs_to("project", "Hydra::Schema::Projects", { name => "project" });
__PACKAGE__->belongs_to(
"release",
"Hydra::Schema::Releases",
{ name => "release_", project => "project" },
);
__PACKAGE__->belongs_to("build", "Hydra::Schema::Builds", { id => "build" });
# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 17:40:21
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:wBLLjLvDq9RWmybMfJiDtQ
# You can replace this text with custom content, and it will be preserved on regeneration
1;

View file

@ -0,0 +1,58 @@
package Hydra::Schema::Releases;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("Releases");
__PACKAGE__->add_columns(
"project",
{
data_type => "text",
default_value => undef,
is_foreign_key => 1,
is_nullable => 0,
size => undef,
},
"name",
{
data_type => "text",
default_value => undef,
is_nullable => 0,
size => undef,
},
"timestamp",
{
data_type => "integer",
default_value => undef,
is_nullable => 0,
size => undef,
},
"description",
{
data_type => "text",
default_value => undef,
is_nullable => 1,
size => undef,
},
);
__PACKAGE__->set_primary_key("project", "name");
__PACKAGE__->belongs_to("project", "Hydra::Schema::Projects", { name => "project" });
__PACKAGE__->has_many(
"releasemembers",
"Hydra::Schema::ReleaseMembers",
{
"foreign.project" => "self.project",
"foreign.release_" => "self.name",
},
);
# Created by DBIx::Class::Schema::Loader v0.04999_06 @ 2009-10-21 17:40:21
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:udsx/5Ic4ul6vDoR6IwFAg
# You can replace this text with custom content, and it will be preserved on regeneration
1;

24
src/root/edit-release.tt Normal file
View file

@ -0,0 +1,24 @@
[% WRAPPER layout.tt title=(create ? "New Release" : "Edit Release") %]
[% PROCESS common.tt %]
[% USE HTML %]
<h1>New Release</h1>
<form action="[% IF create %][% c.uri_for('/project' project.name 'create-release/submit') %][% ELSE %][% c.uri_for('/project' project.name 'release' release.name 'submit') %][% END %]" method="post">
<table class="layoutTable">
<tr>
<th>Identifier:</th>
<td><input type="text" class="string" name="name" [% HTML.attributes(value => release.name) %] /></td>
</tr>
<tr>
<th>Description:</th>
<td><input type="text" class="string" name="description" [% HTML.attributes(value => release.description) %] /></td>
</tr>
</table>
<p><button type="submit"><img src="/static/images/success.gif" />[%IF create %]Create[% ELSE %]Apply changes[% END %]</button></p>
</form>
[% END %]

View file

@ -6,7 +6,7 @@
[% IF c.user_exists %]
<p>
[<a href="[% c.uri_for('/project' project.name 'releases' 'create') %]">Create a release</a>]
[<a href="[% c.uri_for('/project' project.name 'create-release') %]">Create a release</a>]
</p>
[% END %]