[Bps-public-commit] r19863 - in Net-Google-Code/trunk/lib/Net/Google/Code: Issue
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed Jun 3 08:56:30 EDT 2009
Author: sunnavy
Date: Wed Jun 3 08:56:30 2009
New Revision: 19863
Modified:
Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm
Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm
Log:
add updated_after arg for search
Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm (original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Issue/Search.pm Wed Jun 3 08:56:30 2009
@@ -8,6 +8,8 @@
with 'Net::Google::Code::Role::HTMLTree';
use Net::Google::Code::Issue;
use Encode;
+use Date::Manip;
+local $ENV{TZ} = 'GMT';
our %CAN_MAP = (
'all' => 1,
@@ -34,6 +36,8 @@
limit => 999_999_999,
load_after_search => 1,
can => 2,
+ colspec => 'ID+Type+Status+Priority+Milestone+Owner+Summary',
+ updated_after => undef,
@_
);
@@ -41,11 +45,24 @@
$args{can} = $CAN_MAP{ $args{can} };
}
+ if ( $args{updated_after} ) {
+ $args{colspec} .= '+Modified' unless $args{colspec} =~ /Modified/;
+
+ # convert updated_after to epoch
+ if ( ref $args{updated_after} ) {
+ $args{updated_after} = $args{updated_after}->epoch;
+ }
+ else {
+ $args{updated_after} = UnixDate( $args{updated_after}, '%o' );
+ }
+ }
+
+
my $mech = $self->mech;
my $url = $self->base_url . 'issues/list?';
for my $type (qw/can q sort colspec/) {
next unless defined $args{$type};
- $url .= $type . '=' . $args{$type} . ';';
+ $url .= $type . '=' . $args{$type} . '&';
}
$self->fetch( $url );
@@ -59,22 +76,33 @@
get only one ticket
my $issue =
Net::Google::Code::Issue->new( project => $self->project, id => $1, );
- $issue->load if $args{load_after_search};
- $self->results( [$issue] );
+ $issue->load if $args{load_after_search} || $args{updated_after};
+ if ( !$args{updated_after} || $issue->updated->epoch > $args{updated_after} ) {
+ $self->results( [$issue] );
+ }
+ else {
+ $self->results( [] );
+ }
}
elsif ( $mech->title =~ /issues/i ) {
# get a ticket list
- my @rows =
- $self->rows( html => $content, limit => $args{limit} );
+ my @rows = $self->rows(
+ html => $content,
+ limit => $args{limit},
+ updated_after => $args{updated_after},
+ );
+
my @issues;
for my $row (@rows) {
my $issue = Net::Google::Code::Issue->new(
project => $self->project,
%$row,
);
- $issue->load if $args{load_after_search};
- push @issues, $issue;
+ $issue->load if $args{load_after_search} || $args{updated_after};
+ if ( !$args{updated_after} || $issue->updated->epoch >= $args{updated_after} ) {
+ push @issues, $issue;
+ }
}
$self->results( \@issues );
}
Modified: Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm
==============================================================================
--- Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm (original)
+++ Net-Google-Code/trunk/lib/Net/Google/Code/Role/Pageable.pm Wed Jun 3 08:56:30 2009
@@ -5,6 +5,10 @@
with 'Net::Google::Code::Role::Fetchable';
with 'Net::Google::Code::Role::HTMLTree';
use Scalar::Util qw/blessed/;
+use Date::Manip;
+use DateTime;
+local $ENV{TZ} = 'GMT';
+
sub rows {
my $self = shift;
@@ -13,15 +17,22 @@
{
html => { type => SCALAR | OBJECT },
limit => {
- type => SCALAR,
+ type => SCALAR | UNDEF,
+ optional => 1,
+ },
+ updated_after => {
+ type => SCALAR | OBJECT | UNDEF,
optional => 1,
},
}
);
+
$args{limit} ||= 999_999_999; # the impossible huge limit
my $tree = $args{html};
$tree = $self->html_tree( html => $tree ) unless blessed $tree;
+ my $updated_after = $args{updated_after};
+
# assuming there's at most 20 columns
my @titles;
my $label_column;
@@ -53,27 +64,41 @@
my $pagination = $tree->look_down( class => 'pagination' );
return unless $pagination;
+
if ( my ( $start, $end, $total ) =
$pagination->as_text =~ /(\d+)\s+-\s+(\d+)\s+of\s+(\d+)/ )
{
- push @rows,
- $self->_rows(
+ # all the rows in a page
+ my @all_rows = $self->_rows(
html => $tree,
titles => \@titles,
label_column => $label_column,
);
+ my $found_number = scalar @all_rows;
+
+ push @rows, grep {
+ my $epoch = UnixDate( $_->{modified}, '%o' );
+ ( $epoch && $args{updated_after} && $epoch < $args{updated_after} ) ? 0 : 1;
+ } @all_rows;
$total = $args{limit} if $args{limit} < $total;
- while ( scalar @rows < $total ) {
+ while ( $found_number < $total ) {
if ( $self->mech->follow_link( text_regex => qr/Next\s+/ ) ) {
if ( $self->mech->response->is_success ) {
- push @rows,
- $self->_rows(
+ my @all_rows = $self->_rows(
html => $self->mech->content,
titles => \@titles,
label_column => $label_column,
- );
+ );
+ $found_number += @all_rows;
+
+ push @rows, grep {
+ my $epoch = UnixDate( $_->{modified}, '%o' );
+ ( $epoch
+ && $args{updated_after}
+ && $epoch < $args{updated_after} ) ? 0 : 1;
+ } @all_rows;
}
else {
die "failed to follow 'Next' link";
@@ -85,6 +110,7 @@
}
}
}
+
if ( scalar @rows > $args{limit} ) {
# this happens when limit is less than the 1st page's number
return @rows[0 .. $args{limit}-1];
More information about the Bps-public-commit
mailing list