[Bps-public-commit] SD branch, master, updated. 4d3a17ab3b24b2eb937d65925169701eb5648db2

jesse jesse at bestpractical.com
Mon May 18 09:39:39 EDT 2009


The branch, master has been updated
       via  4d3a17ab3b24b2eb937d65925169701eb5648db2 (commit)
       via  d0a99c3955fd54b78009c9b4e0de16e55f03c6a2 (commit)
      from  11425496351bfe55d6967a37d3dd4df8be2d54e5 (commit)

Summary of changes:
 lib/App/SD/ForeignReplica.pm            |    2 +-
 lib/App/SD/Replica/gcode.pm             |   12 +---
 lib/App/SD/Replica/gcode/PullEncoder.pm |  125 ++++++++-----------------------
 lib/App/SD/Replica/rt.pm                |    6 --
 lib/App/SD/Replica/rt/PullEncoder.pm    |    2 +-
 lib/App/SD/Replica/trac.pm              |    8 --
 6 files changed, 36 insertions(+), 119 deletions(-)

- Log -----------------------------------------------------------------
commit d0a99c3955fd54b78009c9b4e0de16e55f03c6a2
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon May 18 09:22:41 2009 -0400

    Removing "upstream_last_txn" API now that it's been killed

diff --git a/lib/App/SD/ForeignReplica.pm b/lib/App/SD/ForeignReplica.pm
index 4348473..3f8c665 100644
--- a/lib/App/SD/ForeignReplica.pm
+++ b/lib/App/SD/ForeignReplica.pm
@@ -68,7 +68,7 @@ sub record_pushed_transactions {
 
         # if the transaction id is older than the id of the last changeset
         # we got from the original source of this changeset, we're done
-        last if $txn->{id} <= $self->upstream_last_txn($args{changeset}->original_source_uuid);
+        last if $txn->{id} <= $self->app_handle->handle->last_changeset_from_source($args{changeset}->original_source_uuid);
         
         # if the transaction from RT is more recent than the most recent
         # transaction we got from the original source of the changeset
diff --git a/lib/App/SD/Replica/rt.pm b/lib/App/SD/Replica/rt.pm
index 107a7e4..5174a8c 100644
--- a/lib/App/SD/Replica/rt.pm
+++ b/lib/App/SD/Replica/rt.pm
@@ -68,12 +68,6 @@ sub get_txn_list_by_date {
     return @txns;
 }
 
-sub upstream_last_txn {
-    my $self = shift;
-    my $uuid = shift;
-    return $self->app_handle->handle->last_changeset_from_source( $uuid);
-}
-
 =head2 uuid
 
 Return the replica's UUID
diff --git a/lib/App/SD/Replica/rt/PullEncoder.pm b/lib/App/SD/Replica/rt/PullEncoder.pm
index 4c546d9..a513ac0 100644
--- a/lib/App/SD/Replica/rt/PullEncoder.pm
+++ b/lib/App/SD/Replica/rt/PullEncoder.pm
@@ -100,7 +100,7 @@ sub find_matching_transactions {
     
     my $ticket_id = $args{ticket}->{$self->sync_source->uuid . '-id'};
 
-     my $latest = $self->sync_source->upstream_last_txn($self->sync_source->uuid_for_remote_id( $ticket_id )) || 0;
+     my $latest = $self->sync_source->app_handle->handle->last_changeset_from_source($self->sync_source->uuid_for_remote_id( $ticket_id )) || 0;
     for my $txn ( sort $rt_handle->get_transaction_ids( parent_id => $ticket_id)) {
         # Skip things calling code told us to skip
         next if $txn < $args{'starting_transaction'}; 
diff --git a/lib/App/SD/Replica/trac.pm b/lib/App/SD/Replica/trac.pm
index 45c384a..16cd548 100644
--- a/lib/App/SD/Replica/trac.pm
+++ b/lib/App/SD/Replica/trac.pm
@@ -47,7 +47,6 @@ sub BUILD {
     $self->trac->ensure_logged_in;
 }
 
-
 sub get_txn_list_by_date {
     my $self   = shift;
     my $ticket = shift;
@@ -58,13 +57,6 @@ sub get_txn_list_by_date {
     my @txns   = map { { id => $_->date->epoch, creator => $_->author, created => $_->date->epoch } } sort {$b->date <=> $a->date }  @{$ticket_obj->history->entries};
     return @txns;
 }
-        
-
-sub upstream_last_txn { 
-    my $self = shift;
-    my $uuid = shift;
-    return $self->app_handle->handle->last_changeset_from_source( $uuid);
-}
 
 =head2 uuid
 

commit 4d3a17ab3b24b2eb937d65925169701eb5648db2
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Mon May 18 09:35:10 2009 -0400

    Snapshot the google code pullencoder

diff --git a/lib/App/SD/Replica/gcode.pm b/lib/App/SD/Replica/gcode.pm
index eb1781e..6a52a9f 100644
--- a/lib/App/SD/Replica/gcode.pm
+++ b/lib/App/SD/Replica/gcode.pm
@@ -13,7 +13,7 @@ use constant push_encoder => 'App::SD::Replica::gcode::PushEncoder';
 
 
 use Prophet::ChangeSet;
-
+has query => ( isa => 'Str', is => 'rw');
 has gcode => ( isa => 'Net::Google::Code', is => 'rw');
 has project => ( isa => 'Str', is => 'rw');
 
@@ -35,7 +35,6 @@ sub BUILD {
     $self->gcode->load();
 }
 
-
 sub get_txn_list_by_date {
     my $self   = shift;
     my $ticket = shift;
@@ -47,13 +46,6 @@ sub get_txn_list_by_date {
         sort {$b->date <=> $a->date }  @{$ticket_obj->comments};
     return @txns;
 }
-        
-
-sub upstream_last_txn { 
-    my $self = shift;
-    my $changeset = shift;
-    return $self->app_handle->handle->last_changeset_from_source( $changeset->original_source_uuid);
-}
 
 =head2 uuid
 
@@ -78,8 +70,6 @@ sub remote_uri_path_for_id {
     return "/ticket/".$id;
 }
 
-
-
 __PACKAGE__->meta->make_immutable;
 no Any::Moose;
 
diff --git a/lib/App/SD/Replica/gcode/PullEncoder.pm b/lib/App/SD/Replica/gcode/PullEncoder.pm
index 5b14902..3eb5a38 100644
--- a/lib/App/SD/Replica/gcode/PullEncoder.pm
+++ b/lib/App/SD/Replica/gcode/PullEncoder.pm
@@ -9,92 +9,27 @@ use DateTime;
 
 has sync_source => (
     isa => 'App::SD::Replica::gcode',
-    is  => 'rw',
-    weak_ref => 1
-);
-
-sub run {
-    ### XXX TODO - can we factor this out?
-    my $self = shift;
-    my %args = validate(
-        @_,
-        {   after    => 1,
-            callback => 1,
-        }
-    );
-    $self->sync_source->log('Finding matching tickets');
-    my @tickets = @{ $self->find_matching_tickets() };
-
-    if ( @tickets == 0 ) {
-        $self->sync_source->log("No tickets found.");
-        return;
-    }
-
-    my @changesets;
-    my $counter = 0;
-    $self->sync_source->log("Discovering ticket history");
-    my $progress = Time::Progress->new();
-    $progress->attr( max => $#tickets );
-    local $| = 1;
-
-    my $last_modified_date;
-
-    for my $ticket (@tickets) {
-        print $progress->report( "%30b %p Est: %E\r", $counter );
-        $self->sync_source->log(
-            "Fetching ticket @{[$ticket->id]} - " . ++$counter . " of " . scalar @tickets );
-
-        $last_modified_date = $ticket->last_modified
-            if ( !$last_modified_date || $ticket->last_modified > $last_modified_date );
-
-        my $ticket_data         = $self->_translate_final_ticket_state($ticket);
-        my $ticket_initial_data = {%$ticket_data};
-        my $txns                = $self->skip_previously_seen_transactions(
-            ticket       => $ticket,
-            transactions => $ticket->history->entries,
-            starting_transaction => $self->sync_source->app_handle->handle->last_changeset_from_source(
- $self->sync_source->uuid_for_remote_id( $ticket->id )
-        )
-
-        );
-    
-        # Walk transactions newest to oldest.
-        for my $txn ( sort { $b->date <=> $a->date } @$txns ) {
-            $self->sync_source->log( $ticket->id . " - Transcoding transaction  @{[$txn->date]} " );
-
-            # the changesets are older than the ones that came before, so they goes first
-            unshift @changesets,
-                grep {defined} $self->transcode_one_txn( $txn, $ticket_initial_data, $ticket_data );
-        }
-
-    }
-
-    $args{callback}->($_) for @changesets;
-    $self->sync_source->record_upstream_last_modified_date($last_modified_date);
-}
+    is  => 'rw');
 
 
 sub _translate_final_ticket_state {
     my $self          = shift;
     my $ticket_object = shift;
-    
-    my $content = $ticket_object->description;
+   
+    warn $ticket_object->reported; 
+    my $created = App::SD::Util::string_to_datetime($ticket_object->reported);
+warn $created;
     my $ticket_data = {
 
         $self->sync_source->uuid . '-id' => $ticket_object->id,
 
         owner => ( $ticket_object->owner || undef ),
-        type => ($ticket_object->type || undef),
-        created     => ( $ticket_object->created->ymd . " " . $ticket_object->created->hms ),
+        created     => ( $created->ymd . " " . $created->hms ),
         reporter    => ( $ticket_object->reporter || undef ),
         status      => $self->translate_status( $ticket_object->status ),
         summary     => ( $ticket_object->summary || undef ),
-        description => ( $content||undef),
-        tags        => ( $ticket_object->keywords || undef ),
-        component   => ( $ticket_object->component || undef ),
-        milestone   => ( $ticket_object->milestone || undef ),
-        priority    => ( $ticket_object->priority || undef ),
-        severity    => ( $ticket_object->severity || undef ),
+        description => ( $ticket_object->description||undef),
+        tags        => ( $ticket_object->labels || undef ),
         cc          => ( $ticket_object->cc || undef ),
     };
 
@@ -110,7 +45,7 @@ sub _translate_final_ticket_state {
 
 =head2 find_matching_tickets QUERY
 
-Returns a Google Code::TicketSearch collection for all tickets found matching your QUERY hash.
+Returns a array of all tickets found matching your QUERY hash.
 
 =cut
 
@@ -120,30 +55,37 @@ sub find_matching_tickets {
    my $last_changeset_seen_dt =   $self->_only_pull_tickets_modified_after();
     $self->sync_source->log("Searching for tickets");
     require Net::Google::Code::Issue::Search;
-    my $search = Net::Google::Code::Issue::Search->new( project =>  $self->sync_source->project, limit => 9999 );
+    my $search = Net::Google::Code::Issue::Search->new( project =>  $self->sync_source->project, limit => '10' ); 
     $search->search();
-    my @results = @{$search->results};
-    foreach my $item (@results) {
-        my $t = $self->sync_source->ticket->load($item);
-        if (!$last_changeset_seen_dt || ($t->last_modified >= $last_changeset_seen_dt)) {
-            push @results, $t;
+warn" did the search";
+    my @base_results = @{$search->results};
+    my @results;
+warn "got the results";
+    foreach my $item (@base_results) {
+        if (!$last_changeset_seen_dt || ($item->last_modified >= $last_changeset_seen_dt)) {
+            warn "Got a ticket ".$item->id;
+            push @results, $item;
         }
     }
     return \@results;
 }
 
-=head2 skip_previously_seen_transactions { ticket => $id, starting_transaction => $num, transactions => \@txns  }
+
+=head2 find_matching_transactions { ticket => $id, starting_transaction => $num  }
 
 Returns a reference to an array of all transactions (as hashes) on ticket $id after transaction $num.
 
 =cut
 
-sub skip_previously_seen_transactions {
+sub find_matching_transactions { 
     my $self = shift;
-    my %args = validate( @_, { ticket => 1, transactions => 1, starting_transaction => 0 } );
-    my @txns;
+    my %args = validate( @_, { ticket => 1, starting_transaction => 1 } );
+    my @raw_txns = @{ $args{ticket}->comments};
 
-    for my $txn ( sort @{ $args{transactions} } ) {
+    my @txns;
+    # XXX TODO make this one loop.
+    for my $txn ( sort @raw_txns) {
+warn $txn;
         my $txn_date = $txn->date->epoch;
 
         # Skip things we know we've already pulled
@@ -152,7 +94,9 @@ sub skip_previously_seen_transactions {
         next if ($self->sync_source->foreign_transaction_originated_locally($txn_date, $args{'ticket'}->id) );
 
         # ok. it didn't originate locally. we might want to integrate it
-        push @txns, $txn;
+        push @txns, { timestamp => $txn->date,
+                      serial => $txn->date->epoch,
+                      object => $txn};
     }
     $self->sync_source->log('Done looking at pulled txns');
     return \@txns;
@@ -222,12 +166,9 @@ sub transcode_create_txn {
             # 1 changeset if it was a normal txn
             # 2 changesets if we needed to to some magic fixups.
 sub transcode_one_txn {
-    my ( $self, $txn, $ticket, $ticket_final ) = (@_);
+    my ( $self, $txn_wrapper, $ticket, $ticket_final ) = (@_);
 
-
-    if ($txn->is_create) {
-        return $self->transcode_create_txn($txn,$ticket,$ticket_final);
-    }
+    my $txn = $txn_wrapper->{object};
 
     my $ticket_uuid = $self->sync_source->uuid_for_remote_id( $ticket->{ $self->sync_source->uuid . '-id' } );
 
@@ -248,7 +189,7 @@ sub transcode_one_txn {
     );
 
 #    warn "right here, we need to deal with changed data that gcode failed to record";
-
+    return; # XXX TODO
     foreach my $prop_change ( values %{ $txn->prop_changes || {} } ) {
         my $new      = $prop_change->new_value;
         my $old      = $prop_change->old_value;

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



More information about the Bps-public-commit mailing list