[Bps-public-commit] r14042 - in Net-Trac/trunk: t

jesse at bestpractical.com jesse at bestpractical.com
Sun Jul 13 20:59:33 EDT 2008


Author: jesse
Date: Sun Jul 13 20:59:32 2008
New Revision: 14042

Added:
   Net-Trac/trunk/lib/Net/Trac/TicketPropChange.pm
   Net-Trac/trunk/t/parse_props.t
Modified:
   Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm
   Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm
   Net-Trac/trunk/t/basic.t

Log:
* We can now download ticket history from the rss feed view

Modified: Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/TicketHistory.pm	Sun Jul 13 20:59:32 2008
@@ -12,16 +12,24 @@
     is => 'ro'
 );
 
+has entries => (
+    isa => 'ArrayRef',
+    is => 'rw');
+
 sub load {
     my $self = shift;
     my $feed = $self->connection->_fetch_feed("/ticket/".$self->ticket."?format=rss");
 
     my @entries = $feed->entries;
+    my @history;
     foreach my $entry (@entries) {
         my $e = Net::Trac::TicketHistoryEntry->new( { connection => $self->connection});
         $e->parse_feed_entry($entry);
+        push @history, $e;
     }
     # http://barnowl.mit.edu/ticket/1?format=rss
+    $self->entries(\@history);
+    return 1;
 }
 
 

Modified: Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm
==============================================================================
--- Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm	(original)
+++ Net-Trac/trunk/lib/Net/Trac/TicketHistoryEntry.pm	Sun Jul 13 20:59:32 2008
@@ -1,19 +1,72 @@
 package Net::Trac::TicketHistoryEntry;
 use Moose;
+use Net::Trac::TicketPropChange;
+
 
 has connection => (
     isa => 'Net::Trac::Connection',
-    is => 'ro'
-    );
+    is  => 'ro'
+);
+
+has prop_changes  => ( isa => 'HashRef', is => 'rw' );
+
+has author   => ( isa => 'Str', is => 'rw' );
+has date     => ( isa => 'DateTime', is => 'rw' );
+has category => ( isa => 'Str', is => 'rw' );
+has content => ( isa => 'Str', is => 'rw');
 
 
 sub parse_feed_entry {
     my $self = shift;
-    my $xml_feed_entry = shift;
-    warn YAML::Dump($xml_feed_entry);
-    
+    my $e    = shift;    # XML::Feed::Entry
+
+    $self->author( $e->author );
+    $self->date( $e->issued );
+    $self->category( $e->category );
+
+    my $desc = $e->content->body;
+
+    if ($desc =~ s/^\s*<ul>\s*?<li>(.*?)<\/li>\s*?<\/ul>//gism) {
+
+        my $props = $1;
+        $self->prop_changes($self->_parse_props($props));
+
+    }
+
+
+    $self->content($desc);
     return 1;
 }
 
+sub _parse_props {
+    my $self = shift;
+    my $raw = shift;
+    my @prop_lines = split(m#</li>\s*<li>#, $raw); 
+    my $props = {};
+foreach my $line (@prop_lines) {
+    my $prop  = '';
+    my $new = '';
+    my $old = '';
+    if ($line =~ /<strong>(.*?)<\/strong> changed from <em>(.*)<\/em> to <em>(.*)<\/em>/) {
+         $prop = $1;
+         $old = $2;
+         $new = $3;
+    }
+    elsif ($line =~ /<strong>(.*?)<\/strong> set to <em>(.*)<\/em>/) {
+         $prop = $1;
+        $old = '';
+         $new = $2;
+    } 
+    elsif ($line =~ /<strong>(.*?)<\/strong> deleted/) {
+         $prop = $1;
+         $new = '';
+    } 
+
+    my $pc = Net::Trac::TicketPropChange->new( property => $prop, new_value => $new, old_value => $old  );
+    $props->{$prop} = $pc; 
+}
+    return $props;
+}
+
 
 1;

Added: Net-Trac/trunk/lib/Net/Trac/TicketPropChange.pm
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/lib/Net/Trac/TicketPropChange.pm	Sun Jul 13 20:59:32 2008
@@ -0,0 +1,8 @@
+package Net::Trac::TicketPropChange;
+use Moose;
+
+has property => (isa => 'Str', is => 'rw');
+has old_value => (isa => 'Str', is => 'rw');
+has new_value => (isa => 'Str', is => 'rw');
+
+1;

Modified: Net-Trac/trunk/t/basic.t
==============================================================================
--- Net-Trac/trunk/t/basic.t	(original)
+++ Net-Trac/trunk/t/basic.t	Sun Jul 13 20:59:32 2008
@@ -12,5 +12,5 @@
 can_ok($ticket, 'load');
 ok($ticket->load(1));
 like($ticket->state->{'summary'}, qr/pony/);
-like($ticket->summary, qr/pony/);
-ok($ticket->history);
+like($ticket->summary, qr/pony/, "The summary looks like a pony");
+ok($ticket->history, "The ticket has some history");

Added: Net-Trac/trunk/t/parse_props.t
==============================================================================
--- (empty file)
+++ Net-Trac/trunk/t/parse_props.t	Sun Jul 13 20:59:32 2008
@@ -0,0 +1,19 @@
+use Test::More qw/no_plan/;
+
+my $props = <<'EOF';
+
+<strong>owner</strong> changed from <em>somebody</em> to <em>jrv</em>.</li>
+    <li><strong>status</strong> changed from <em>new</em> to <em>assigned</em>.</li>
+    <li><strong>type</strong> changed from <em>defect</em> to <em>enhancement</em>.</li>
+    <li><strong>description</strong> set to <em>cry</em>
+
+EOF
+
+use_ok('Net::Trac::TicketHistoryEntry');
+
+my $e = Net::Trac::TicketHistoryEntry->new();
+my $props = $e->_parse_props($props);
+is(scalar keys %$props, 4, "Four properties");
+my @keys = sort (qw(owner status type description));
+is_deeply([sort keys %$props], [sort @keys]);
+



More information about the Bps-public-commit mailing list