[Bps-public-commit] r19731 - in Net-Google-Code/trunk: lib/Net/Google/Code

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed May 20 00:15:18 EDT 2009


Author: sunnavy
Date: Wed May 20 00:15:18 2009
New Revision: 19731

Modified:
   Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm
   Net-Google-Code/trunk/t/02.issue.t

Log:
try our best to get the updates of initial comment

Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue.pm	Wed May 20 00:15:18 2009
@@ -168,7 +168,16 @@
 
     # extract comments
     my @comments_tag = $tree->look_down( class => 'vt issuecomment' );
-    my @comments = Net::Google::Code::Issue::Comment->new(
+    my @comments;
+    for my $tag (@comments_tag) {
+        next unless $tag->look_down( class => 'author' );
+        my $comment =
+          Net::Google::Code::Issue::Comment->new( project => $self->project );
+        $comment->parse($tag);
+        push @comments, $comment;
+    }
+
+    my $initial_comment = Net::Google::Code::Issue::Comment->new(
         project     => $self->project,
         sequence    => 0,
         date        => $self->reported,
@@ -176,13 +185,35 @@
         content     => $self->description,
         attachments => $self->attachments,
     );
-    for my $tag (@comments_tag) {
-        next unless $tag->look_down( class => 'author' );
-        my $comment =
-          Net::Google::Code::Issue::Comment->new( project => $self->project );
-        $comment->parse($tag);
-        push @comments, $comment;
+
+    my @initial_labels = @{$self->labels};
+    my %meta = map { $_ => 1 } qw/summary status cc owner/;
+    for my $c ( reverse @comments ) {
+        my $updates = $c->updates;
+        for ( keys %meta ) {
+            # once these changes, we can't know the inital value
+            delete $meta{$_} if exists $updates->{$_};
+        }
+        if ( $updates->{labels} ) {
+            my @labels = @{$updates->{labels}};
+            for my $label (@labels) {
+                if ( $label =~ /^-(.*)$/ ) {
+                    unshift @initial_labels, $1;
+                }
+                else {
+                    @initial_labels = grep { $_ ne $label } @initial_labels;
+                }
+            }
+        }
+    }
+
+    $initial_comment->updates->{labels} = \@initial_labels;
+    for ( keys %meta ) {
+        $initial_comment->updates->{$_} = $self->$_;
     }
+
+    unshift @comments, $initial_comment;
+
     $self->comments( \@comments );
 
 }

Modified: Net-Google-Code/trunk/t/02.issue.t
==============================================================================
--- Net-Google-Code/trunk/t/02.issue.t	(original)
+++ Net-Google-Code/trunk/t/02.issue.t	Wed May 20 00:15:18 2009
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 17;
+use Test::More tests => 18;
 use Test::MockModule;
 
 # $content is a real page: http://code.google.com/p/chromium/issues/detail?id=14
@@ -70,6 +70,17 @@
 is( $issue->comments->[0]->sequence, 0, 'comment 0 is for the actual create' );
 is( scalar @{ $issue->comments->[0]->attachments },
     3, 'comment 0 has 3 attachments' );
+is_deeply(
+    $issue->comments->[0]->updates,
+    {
+        'owner'   => 'all-bugs-test at chromium.org',
+        'summary' => 'Proxy settings for installer',
+        'labels' =>
+          [ 'Area-Unknown', 'Type-Bug', 'Pri-2', 'OS-All', 'Foo-Bar-Baz' ]
+    },
+    'comment 0 updates'
+);
+
 is( $issue->comments->[1]->sequence, 1, 'sequence of comment 1 is 1' );
 # seems comments 2 and 3 are deleted
 is( $issue->comments->[2]->sequence, 4, 'sequence of comment 2 is 4' ); 



More information about the Bps-public-commit mailing list