[Bps-public-commit] App-Changeloggr branch, master, updated. 73098264db54e0de04650aef67d4ef82f57c5ae4

Alex M Vandiver alexmv at bestpractical.com
Tue Mar 31 16:13:03 EDT 2009


The branch, master has been updated
       via  73098264db54e0de04650aef67d4ef82f57c5ae4 (commit)
      from  5e6e70ee1db37d3acfbc9b1d9796a35cef82ef52 (commit)

Summary of changes:
 lib/App/Changeloggr/Action/AddChanges.pm      |   20 +++++++-------------
 lib/App/Changeloggr/LogFormat.pm              |   10 ++++++++--
 lib/App/Changeloggr/Model/ChangeCollection.pm |   18 +++++++++++++-----
 lib/App/Changeloggr/Model/Changelog.pm        |   20 ++++++++++++++------
 4 files changed, 42 insertions(+), 26 deletions(-)

- Log -----------------------------------------------------------------
commit 73098264db54e0de04650aef67d4ef82f57c5ae4
Author: Alex Vandiver <alexmv at mit.edu>
Date:   Tue Mar 31 16:12:48 2009 -0400

    Make changes into an upload form

diff --git a/lib/App/Changeloggr/Action/AddChanges.pm b/lib/App/Changeloggr/Action/AddChanges.pm
index 123b6b6..d22f8a6 100644
--- a/lib/App/Changeloggr/Action/AddChanges.pm
+++ b/lib/App/Changeloggr/Action/AddChanges.pm
@@ -11,9 +11,9 @@ use Jifty::Action schema {
 
     param changes =>
         type is 'text',
-        render as 'textarea',
+        render as 'upload',
         is mandatory,
-        hints is 'Currently we only accept the output of: git log --pretty=fuller --stat';
+        hints is 'Formats we accept: git log --pretty=fuller --stat, svn log, or svn log --xml';
 };
 
 sub get_changelog {
@@ -41,23 +41,17 @@ sub validate_admin_token {
     }
 }
 
-sub validate_changes {
+sub take_action {
     my $self = shift;
-    my $text = shift;
 
-    my $parser = App::Changeloggr::LogFormat->new( text => $text );
-    if ( $parser ) {
-        return $self->validation_ok( 'changes' );
-    } else {
+    my $parser = App::Changeloggr::LogFormat->new( file => $self->argument_value('changes') );
+    $self->argument_value( changes => undef );
+    unless ($parser) {
         return $self->validation_error( changes => "That doesn't look like a log format we recognize." );
     }
-}
 
-sub take_action {
-    my $self = shift;
     my $changelog = $self->get_changelog;
-
-    my $changes = $changelog->parse_and_add_changes($self->argument_value('changes'));
+    my $changes = $changelog->add_changes( $parser );
 
     if ($changes->count) {
         $self->result->message(_("Added your %quant(%1,change)!", $changes->count));
diff --git a/lib/App/Changeloggr/LogFormat.pm b/lib/App/Changeloggr/LogFormat.pm
index 3feefab..7c03a25 100644
--- a/lib/App/Changeloggr/LogFormat.pm
+++ b/lib/App/Changeloggr/LogFormat.pm
@@ -5,14 +5,20 @@ use warnings;
 sub new {
     my $class = shift;
     my %args = @_;
-    return unless $args{text};
+    return unless $args{text} or $args{file};
+
+    if (my $fh = delete $args{file}) {
+        $args{text} = do { local $/; <$fh>};
+    }
 
     $args{text} =~ s/^\s+//;
     $args{text} =~ s/\r\n/\n/g;
 
+    return unless $args{text} =~ /\S/;
+
     if ($class eq "App::Changeloggr::LogFormat") {
         for my $format (App::Changeloggr->log_formats) {
-            return $format->new( @_ ) if $format->matches( @_ );
+            return $format->new( %args ) if $format->matches( %args );
         }
         return undef;
     }
diff --git a/lib/App/Changeloggr/Model/ChangeCollection.pm b/lib/App/Changeloggr/Model/ChangeCollection.pm
index 1aebe78..4ecc0de 100644
--- a/lib/App/Changeloggr/Model/ChangeCollection.pm
+++ b/lib/App/Changeloggr/Model/ChangeCollection.pm
@@ -13,10 +13,19 @@ sub create_from_text {
         changelog => { isa => 'App::Changeloggr::Model::Changelog' },
     });
 
-    my $text      = $args{text};
-    my $changelog = $args{changelog};
+    my $parser = App::Changeloggr::LogFormat->new( text => delete $args{text} );
+    return $self->create_from_parser( %args, parser => $parser );
+}
 
-    my $parser = App::Changeloggr::LogFormat->new( text => $text );
+sub create_from_parser {
+    my $self = shift;
+    my %args = validate(@_, {
+        parser    => { isa => 'App::Changeloggr::LogFormat' },
+        changelog => { isa => 'App::Changeloggr::Model::Changelog' },
+    });
+
+    my $parser    = $args{parser};
+    my $changelog = $args{changelog};
 
     while (my $fields = $parser->next_match) {
         my $change = App::Changeloggr::Model::Change->new;
@@ -28,8 +37,7 @@ sub create_from_text {
 
         if ($ok) {
             $self->add_record($change);
-        }
-        else {
+        } else {
             warn "Unable to create Change: $msg";
         }
     }
diff --git a/lib/App/Changeloggr/Model/Changelog.pm b/lib/App/Changeloggr/Model/Changelog.pm
index 049c202..819ce50 100644
--- a/lib/App/Changeloggr/Model/Changelog.pm
+++ b/lib/App/Changeloggr/Model/Changelog.pm
@@ -41,15 +41,23 @@ sub current_user_can {
     return $self->SUPER::current_user_can($right, %args);
 }
 
-sub parse_and_add_changes {
+sub add_changes {
     my $self = shift;
-    my $text = shift;
+    my $arg = shift;
 
     my $changes = M('ChangeCollection');
-    $changes->create_from_text(
-        text      => $text,
-        changelog => $self,
-    );
+    if (ref $arg) {
+        $changes->create_from_parser(
+            parser    => $arg,
+            changelog => $self,
+        );
+    } else {
+        $changes->create_from_text(
+            text      => $arg,
+            changelog => $self,
+        );
+    }
+    
 
     return $changes;
 }

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list