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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Fri Dec 26 03:24:08 EST 2008


Author: sunnavy
Date: Fri Dec 26 03:24:08 2008
New Revision: 17369

Modified:
   Net-Google-Code/trunk/   (props changed)
   Net-Google-Code/trunk/lib/Net/Google/Code/Ticket.pm

Log:
 r18307 at sunnavys-mb:  sunnavy | 2008-12-26 14:01:24 +0800
 parse metadata and labels


Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Ticket.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Ticket.pm	(original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Ticket.pm	Fri Dec 26 03:24:08 2008
@@ -16,6 +16,13 @@
 has state => (
     isa => 'HashRef',
     is  => 'rw',
+    default => sub { {} },
+);
+
+has labels => (
+    isa => 'HashRef',
+    is  => 'rw',
+    default => sub { {} },
 );
 
 has comments => (
@@ -23,7 +30,7 @@
     is => 'rw',
 );
 
-our @PROPS = qw(status owner closed cc summary);
+our @PROPS = qw(status owner closed cc summary description);
 
 for my $prop (@PROPS) {
     no strict 'refs'; ## no critic
@@ -40,14 +47,54 @@
     $self->connection->_fetch( "/issues/detail?id=" . $id );
 
     my $content = $self->connection->mech->content;
+    require HTML::TreeBuilder;
+    my $tree    = HTML::TreeBuilder->new;
+    $tree->parse_content($content);
+    $tree->elementify;
+    my ($meta) = $tree->look_down( id => 'issuemeta' );
+    my @meta = $meta->find_by_tag_name('tr');
+    for my $meta (@meta) {
+
+        my ( $key, $value );
+        if ( my $k = $meta->find_by_tag_name('th') ) {
+            my $v         = $meta->find_by_tag_name('td');
+            my $k_content = $k->content_array_ref->[0];
+            while ( ref $k_content ) {
+                $k_content = $k_content->content_array_ref->[0];
+            }
+            $key = $k_content;    # $key is like 'Status:#'
+            $key =~ s/:.$//;      # s/:#$// doesn't work, no idea why
+
+            if ($v) {
+                my $v_content = $v->content_array_ref->[0];
+                while ( ref $v_content ) {
+                    $v_content = $v_content->content_array_ref->[0];
+                }
+                $value = $v_content;
+                $value =~ s/^\s+//;
+                $value =~ s/\s+$//;
+            }
+            $self->state->{lc $key} = $value;
+        }
+        else {
+            my $href = $meta->find_by_tag_name('a')->attr_get_i('href');
+
+# from issue tracking faq:
+# The prefix before the first dash is the key, and the part after it is the value.
+            if ( $href =~ /list\?q=label:([^-]+?)-(.+)/ ) {
+                ( $key, $value ) = ( $1, $2 );
+            }
+            elsif ( $href =~ /list\?q=label:([^-]+)$/ ) {
+                $key = $1;
+            }
+            else {
+                warn "can't parse label from $href";
+            }
+            $self->labels->{$key} = $value;
+        }
+    }
 
-    my $stateref;
-    #XXX scrap $content to get state and comments
-
-    return unless $stateref;
-    $self->state( $stateref->{$id} );
     return $id;
-
 }
 
 sub _fetch_new_ticket_metadata {



More information about the Bps-public-commit mailing list