[Bps-public-commit] r12503 - in sd/trunk: bin lib/App/SD/Replica/RT

jesse at bestpractical.com jesse at bestpractical.com
Sat May 17 12:41:29 EDT 2008


Author: jesse
Date: Sat May 17 12:41:28 2008
New Revision: 12503

Modified:
   sd/trunk/bin/sd
   sd/trunk/lib/App/SD/Replica/RT.pm
   sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm

Log:
* roundtripping with rt.cpan.org
* ticket history works better
* status now interops

Modified: sd/trunk/bin/sd
==============================================================================
--- sd/trunk/bin/sd	(original)
+++ sd/trunk/bin/sd	Sat May 17 12:41:28 2008
@@ -1,4 +1,4 @@
-#!/usr/bin/env perl 
+#!/usr/bin/perl 
 use warnings;
 use strict;
 
@@ -166,9 +166,10 @@
         print "No comments found\n";
     }
 
-    for (@{$record->comments}) {
-        print "comment id: ".$_->uuid."\n";
-        print "Content:\n".$_->prop('content')."\n";
+    for (sort { $a->prop('date') cmp $b->prop('date') } @{$record->comments}) {
+        print "id: ".$_->luid." (".$_->uuid.")\n";
+        print "date: ".$_->prop('date')."\n";
+        print $_->prop('content')."\n";
     }
 
 }

Modified: sd/trunk/lib/App/SD/Replica/RT.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/RT.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/RT.pm	Sat May 17 12:41:28 2008
@@ -63,7 +63,6 @@
 
 =head2 setup
 
-Open a connection to the SVN source identified by C<$self->url>.
 
 =cut
 
@@ -373,6 +372,9 @@
         } else {
             $attr{$key} = $props{$key};
         }
+        if ( $key eq 'status' ) {
+            $attr{$key} =~ s/^closed$/resolved/;
+        }
     }
     return \%attr;
 }

Modified: sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm	Sat May 17 12:41:28 2008
@@ -17,11 +17,15 @@
     my %args = validate( @_, { ticket => 1, transactions => 1, attachments => 0 } );
 
     $args{'ticket'}->{'id'} =~ s/^ticket\///g;
+    for (qw(Queue id)) {
+    $args{'ticket'}->{ $self->sync_source->uuid . '-'.lc($_) } = delete $args{'ticket'}->{$_};
+    }
 
     my $ticket = $args{'ticket'};
     map { delete $ticket->{$_} if (!defined $ticket->{$_}  || $ticket->{$_} eq '') } keys %$ticket;
     map { $ticket->{$_} = $self->date_to_iso( $ticket->{$_} ) } qw(Created Resolved Told LastUpdated Starts Started);
     map { $ticket->{$_} =~ s/ minutes$// if defined $ticket->{$_} } qw(TimeWorked TimeLeft TimeEstimated);
+    $ticket->{'Status'} =~ s/^(resolved|rejected)$/closed/;
     my $create_state = $ticket;
 
     my @changesets;
@@ -44,8 +48,8 @@
                 }
             );
 
-            if ( ( $txn->{'Ticket'} ne $ticket->{id} ) && $txn->{'Type'} !~ /^(?:Comment|Correspond)$/ ) {
-                warn "Skipping a data change from a merged ticket" . $txn->{'Ticket'} . ' vs ' . $ticket->{id};
+            if ( ( $txn->{'Ticket'} ne $ticket->{$self->sync_source->uuid . '-id'} ) && $txn->{'Type'} !~ /^(?:Comment|Correspond)$/ ) {
+                warn "Skipping a data change from a merged ticket" . $txn->{'Ticket'} . ' vs ' . $ticket->{$self->sync_source->uuid . '-id'};
                 next;
             }
 
@@ -79,10 +83,11 @@
         }
     );
     $change->add_prop_change( name => 'content_type', old  => undef, new  => $args{'attachment'}->{'ContentType'});
+    $change->add_prop_change( name => 'date', old  => undef, new  => $self->date_to_iso($args{'txn'}->{'Created'}));
     $change->add_prop_change( name => 'creator', old  => undef, new  => $self->resolve_user_id_to( email => $args{'attachment'}->{'Creator'}));
     $change->add_prop_change( name => 'content', old  => undef, new  => $args{'attachment'}->{'Content'});
     $change->add_prop_change( name => 'name', old  => undef, new  => $args{'attachment'}->{'Filename'});
-    $change->add_prop_change( name => 'ticket', old  => undef, new  => $self->sync_source->uuid_for_remote_id( $args{'ticket'}->{'id'} ));
+    $change->add_prop_change( name => 'ticket', old  => undef, new  => $self->sync_source->uuid_for_remote_id( $args{'ticket'}->{ $self->sync_source->uuid . '-id'} ));
     $args{'changeset'}->add_change( { change => $change } );
 }
 
@@ -99,6 +104,9 @@
     my %args = validate( @_, { ticket => 1, txn => 1, create_state => 1, changeset => 1 } );
 
     $args{txn}->{'Type'} = 'Set';
+        for my $type(qw(NewValue OldValue)) {
+                $args{'txn'}->{$type} =~ s/^(resolved|rejected)$/closed/;
+        }
     return $self->_recode_txn_Set(%args);
 }
 
@@ -119,13 +127,13 @@
 
     my $change = Prophet::Change->new(
         {   record_type   => 'ticket',
-            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{'id'} ),
+            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{$self->sync_source->uuid . '-id'} ),
             change_type => 'update_file'
         }
     );
 
     if ( $args{txn}->{Field} eq 'Queue' ) {
-        my $current_queue = $args{ticket}->{'Queue'};
+        my $current_queue = $args{ticket}->{$self->sync_source->uuid .'-queue'};
         my $user          = $args{txn}->{Creator};
         if ( $args{txn}->{Description} =~ /Queue changed from (.*) to $current_queue by $user/ ) {
             $args{txn}->{OldValue} = $1;
@@ -135,7 +143,6 @@
     } elsif ( $args{txn}->{Field} eq 'Owner' ) {
         $args{'txn'}->{NewValue} = $self->resolve_user_id_to( name => $args{'txn'}->{'NewValue'} );
         $args{'txn'}->{OldValue} = $self->resolve_user_id_to( name => $args{'txn'}->{'OldValue'} );
-
     }
 
     $args{'changeset'}->add_change( { change => $change } );
@@ -143,7 +150,7 @@
         $args{'create_state'}->{ $args{txn}->{Field} } = $args{txn}->{'OldValue'};
     } else {
         $args{'create_state'}->{ $args{txn}->{Field} } = $args{txn}->{'OldValue'};
-        warn $args{'create_state'}->{ $args{txn}->{Field} } . " != " . $args{txn}->{'NewValue'} . "\n\n" . YAML::Dump( \%args );
+        warn $args{'create_state'}->{ $args{txn}->{Field} } . " != " . $args{txn}->{'NewValue'} . "\n\n" . YAML::Dump( \%args ); use YAML;
     }
     $change->add_prop_change(
         name => $args{txn}->{'Field'},
@@ -164,13 +171,11 @@
 
     my $change = Prophet::Change->new(
         {   record_type   => 'ticket',
-            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{'id'} ),
+            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{$self->sync_source->uuid . '-id'} ),
             change_type => 'add_file'
         }
     );
 
-    $args{'create_state'}->{ $self->sync_source->uuid . '-id' } = delete $args{'create_state'}->{'id'};
-
     $args{'changeset'}->add_change( { change => $change } );
     for my $name ( keys %{ $args{'create_state'} } ) {
 
@@ -198,7 +203,7 @@
 
     my $change = Prophet::Change->new(
         {   record_type   => 'ticket',
-            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{'id'} ),
+            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{$self->sync_source->uuid . '-id'} ),
             change_type => 'update_file'
         }
     );
@@ -220,10 +225,13 @@
             change_type => 'add_file'
         }
     );
+
+        $change->add_prop_change( name => 'date', old  => undef, new  => $self->date_to_iso($args{'txn'}->{'Created'}));
+
     $change->add_prop_change( name => 'type', old  => undef, new  => $args{'txn'}->{'Type'});
     $change->add_prop_change( name => 'creator', old  => undef, new  => $self->resolve_user_id_to( email => $args{'txn'}->{'Creator'}));
     $change->add_prop_change( name => 'content', old  => undef, new  => $args{'txn'}->{'Content'});
-    $change->add_prop_change( name => 'ticket', old  => undef, new  => $self->sync_source->uuid_for_remote_id( $args{'ticket'}->{'id'} ));
+    $change->add_prop_change( name => 'ticket', old  => undef, new  => $self->sync_source->uuid_for_remote_id( $args{'ticket'}->{ $self->sync_source->uuid . '-id'} ));
     $args{'changeset'}->add_change( { change => $change } );
 }
 
@@ -246,7 +254,7 @@
 
     my $change = Prophet::Change->new(
         {   record_type   => 'ticket',
-            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{'id'} ),
+            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{$self->sync_source->uuid . '-id'} ),
             change_type => 'update_file'
         }
     );
@@ -288,7 +296,7 @@
 
     my $change = Prophet::Change->new(
         {   record_type   => 'ticket',
-            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{'id'} ),
+            record_uuid   => $self->sync_source->uuid_for_remote_id( $args{'create_state'}->{$self->sync_source->uuid . '-id'} ),
             change_type => 'update_file'
         }
     );
@@ -374,7 +382,7 @@
     timeleft        => 'time_left',
     lastupdated     => '_delete',
     created         => '_delete',            # we should be porting the create date as a metaproperty
-
+    Queue           => 'queue',
 );
 
 sub translate_prop_names {
@@ -388,14 +396,11 @@
         for my $prop ( $change->prop_changes ) {
             next if ( ( $PROP_MAP{ lc( $prop->name ) } || '' ) eq '_delete' );
             $prop->name( $PROP_MAP{ lc( $prop->name ) } ) if $PROP_MAP{ lc( $prop->name ) };
-
-            if ( $prop->name eq 'id' ) {
-                $prop->old_value( $prop->old_value . '@' . $changeset->original_source_uuid )
-                    if ( $prop->old_value || '' ) =~ /^\d+$/;
-                $prop->old_value( $prop->new_value . '@' . $changeset->original_source_uuid )
-                    if ( $prop->new_value || '' ) =~ /^\d+$/;
-
-            }
+#
+#            if ( $prop->name eq 'id' || $prop->name eq 'queue') {
+#                $prop->old_value( $prop->old_value . '@' . $changeset->original_source_uuid ) if ( $prop->old_value);
+#                $prop->old_value( $prop->new_value . '@' . $changeset->original_source_uuid ) if ( $prop->new_value);
+#            }
 
             if ( $prop->name =~ /^cf-(.*)$/ ) {
                 $prop->name( 'custom-' . $1 );



More information about the Bps-public-commit mailing list