From 851a4dff4dffc592eb7d0306cb515d40e814871f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 23 Oct 2009 09:58:23 +0000 Subject: [PATCH] * Creating releases. --- src/lib/Hydra/Controller/Project.pm | 29 ++++++++++++- src/lib/Hydra/Controller/Release.pm | 37 ++++++++++++++++ src/lib/Hydra/Schema/ReleaseMembers.pm | 58 ++++++++++++++++++++++++++ src/lib/Hydra/Schema/Releases.pm | 58 ++++++++++++++++++++++++++ src/root/edit-release.tt | 24 +++++++++++ src/root/releases.tt | 2 +- 6 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 src/lib/Hydra/Controller/Release.pm create mode 100644 src/lib/Hydra/Schema/ReleaseMembers.pm create mode 100644 src/lib/Hydra/Schema/Releases.pm create mode 100644 src/root/edit-release.tt diff --git a/src/lib/Hydra/Controller/Project.pm b/src/lib/Hydra/Controller/Project.pm index d47eb049..2a6c6e05 100644 --- a/src/lib/Hydra/Controller/Project.pm +++ b/src/lib/Hydra/Controller/Project.pm @@ -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])); } diff --git a/src/lib/Hydra/Controller/Release.pm b/src/lib/Hydra/Controller/Release.pm new file mode 100644 index 00000000..d25c21da --- /dev/null +++ b/src/lib/Hydra/Controller/Release.pm @@ -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; diff --git a/src/lib/Hydra/Schema/ReleaseMembers.pm b/src/lib/Hydra/Schema/ReleaseMembers.pm new file mode 100644 index 00000000..9c927001 --- /dev/null +++ b/src/lib/Hydra/Schema/ReleaseMembers.pm @@ -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; diff --git a/src/lib/Hydra/Schema/Releases.pm b/src/lib/Hydra/Schema/Releases.pm new file mode 100644 index 00000000..bd3bc4e6 --- /dev/null +++ b/src/lib/Hydra/Schema/Releases.pm @@ -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; diff --git a/src/root/edit-release.tt b/src/root/edit-release.tt new file mode 100644 index 00000000..1461a92e --- /dev/null +++ b/src/root/edit-release.tt @@ -0,0 +1,24 @@ +[% WRAPPER layout.tt title=(create ? "New Release" : "Edit Release") %] +[% PROCESS common.tt %] +[% USE HTML %] + +

New Release

+ +
+ + + + + + + + + + +
Identifier: release.name) %] />
Description: release.description) %] />
+ +

+ +
+ +[% END %] diff --git a/src/root/releases.tt b/src/root/releases.tt index 6426d530..40d741ac 100644 --- a/src/root/releases.tt +++ b/src/root/releases.tt @@ -6,7 +6,7 @@ [% IF c.user_exists %]

-[Create a release] +[Create a release]

[% END %]