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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue May 26 23:26:52 EDT 2009


The branch, master has been updated
       via  bdb68aeffe760120fc63b1322febd2e1cdf69852 (commit)
       via  395c8bedb026d86349466e5e385e93242176d9fc (commit)
      from  c074790c16eac9a6cc4b07f2026eb94dde47666d (commit)

Summary of changes:
 lib/App/SD/Replica/gcode/PushEncoder.pm |  115 +++++++++++++++++++++----------
 1 files changed, 77 insertions(+), 38 deletions(-)

- Log -----------------------------------------------------------------
commit 395c8bedb026d86349466e5e385e93242176d9fc
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed May 27 11:09:10 2009 +0800

    push for gcode initially works except the sign in part

diff --git a/lib/App/SD/Replica/gcode/PushEncoder.pm b/lib/App/SD/Replica/gcode/PushEncoder.pm
index 19cdbc8..247a6ac 100644
--- a/lib/App/SD/Replica/gcode/PushEncoder.pm
+++ b/lib/App/SD/Replica/gcode/PushEncoder.pm
@@ -1,13 +1,15 @@
 package App::SD::Replica::gcode::PushEncoder;
-use Any::Moose; 
+use Any::Moose;
 use Params::Validate;
 use Path::Class;
-use Time::HiRes qw/usleep/;
+use Net::Google::Code::Issue;
+use Net::Google::Code;
 
 has sync_source => (
     isa => 'App::SD::Replica::gcode',
     is  => 'rw',
 );
+my $gcode;
 
 sub integrate_change {
     my $self = shift;
@@ -16,57 +18,83 @@ sub integrate_change {
         { isa => 'Prophet::Change' },
         { isa => 'Prophet::ChangeSet' }
     );
-    my ($id, $record);
-
-    # if the original_sequence_no of this changeset is <= 
-    # the last changeset our sync source for the original_sequence_no, we can skip it.
-    # XXX TODO - this logic should be at the changeset level, not the cahnge level, as it applies to all
-    # changes in the changeset
+    my ( $id, $record );
+
+# if the original_sequence_no of this changeset is <=
+# the last changeset our sync source for the original_sequence_no, we can skip it.
+# XXX TODO - this logic should be at the changeset level, not the cahnge level, as it applies to all
+# changes in the changeset
+#    warn $self->sync_source->app_handle->handle->last_changeset_from_source(
+#        $changeset->original_source_uuid ), "\n";
     return
       if $self->sync_source->app_handle->handle->last_changeset_from_source(
         $changeset->original_source_uuid ) >= $changeset->original_sequence_no;
 
     my $before_integration = time();
+    $gcode ||= Net::Google::Code->new(
+        project  => $self->sync_source->project,
+    );
 
     eval {
         if (    $change->record_type eq 'ticket'
-            and $change->change_type eq 'add_file' ) {
+            and $change->change_type eq 'add_file' )
+        {
             $id = $self->integrate_ticket_create( $change, $changeset );
             $self->sync_source->record_remote_id_for_pushed_record(
                 uuid      => $change->record_uuid,
-                remote_id => $id);
+                remote_id => $id,
+            );
         }
         elsif ( $change->record_type eq 'attachment'
-            and $change->change_type eq 'add_file') {
+            and $change->change_type eq 'add_file' )
+        {
             $id = $self->integrate_attachment( $change, $changeset );
         }
         elsif ( $change->record_type eq 'comment'
-            and $change->change_type eq 'add_file' ) {
+            and $change->change_type eq 'add_file' )
+        {
             $id = $self->integrate_comment( $change, $changeset );
         }
         elsif ( $change->record_type eq 'ticket' ) {
             $id = $self->integrate_ticket_update( $change, $changeset );
         }
         else {
-            $self->sync_source->log('I have no idea what I am doing for '.$change->record_uuid);
-            return undef;
+            $self->sync_source->log(
+                'I have no idea what I am doing for ' . $change->record_uuid );
+            return;
         }
 
         $self->sync_source->record_pushed_transactions(
             start_time => $before_integration,
-            ticket    => $id,
-            changeset => $changeset);
+            ticket     => $id,
+            changeset  => $changeset,
+        );
     };
 
-    if (my $err = $@) {
-        $self->sync_source->log("Push error: ".$err);
+    if ( my $err = $@ ) {
+        $self->sync_source->log( "Push error: " . $err );
     }
 
-#    usleep(1100);
-
     return $id;
 }
 
+sub integrate_ticket_update {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+
+    # Figure out the remote site's ticket ID for this change's record
+    my $remote_ticket_id =
+      $self->sync_source->remote_id_for_uuid( $change->record_uuid );
+    my $ticket = $gcode->issue();
+    $ticket->load($remote_ticket_id);
+    $ticket->update( %{ $self->_recode_props_for_integrate($change) }, );
+    return $remote_ticket_id;
+}
+
 sub integrate_ticket_create {
     my $self = shift;
     my ( $change, $changeset ) = validate_pos(
@@ -76,32 +104,33 @@ sub integrate_ticket_create {
     );
 
     # Build up a ticket object out of all the record's attributes
-    my $ticket =
-      Net::Google::Code::Issue->new( project => $self->sync_source->project );
-    my $id = $ticket->create( %{ $self->_recode_props_for_integrate($change) });
+    my $ticket = $gcode->issue;
+    my $id =
+      $ticket->create( %{ $self->_recode_props_for_integrate($change) } );
 
     return $id;
 }
 
 sub integrate_comment {
     my $self = shift;
-    my ($change, $changeset) = validate_pos( @_, { isa => 'Prophet::Change' }, {isa => 'Prophet::ChangeSet'} );
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
 
     # Figure out the remote site's ticket ID for this change's record
 
     my %props = map { $_->name => $_->new_value } $change->prop_changes;
 
     my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
-    my $ticket = Net::Google::Code::Issue->new(
-        project => $self->sync_source->project,
-        id    => $ticket_id,
-    );
+    my $ticket = $gcode->issue( id => $ticket_id );
 
-    my %content = ( message => $props{'content'}, );
+    my %content = ( comment => $props{'content'}, );
 
-    $ticket->update( %content);
+    $ticket->update(%content);
     return $ticket_id;
-} 
+}
 
 sub integrate_attachment {
     my ( $self, $change, $changeset ) = validate_pos(
@@ -113,17 +142,14 @@ sub integrate_attachment {
 
     my %props     = map { $_->name => $_->new_value } $change->prop_changes;
     my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
-    my $ticket    = Net::Google::Code::Issue->new(
-        project => $self->sync_source->project,
-        id      => $ticket_id,
-    );
+    my $ticket    = $gcode->issue( id => $ticket_id, );
 
     my $tempdir = File::Temp::tempdir( CLEANUP => 1 );
     my $file = file( $tempdir => ( $props{'name'} || 'unnamed' ) );
     my $fh = $file->openw;
     print $fh $props{content};
     close $fh;
-    my %content = ( message => '(See attachments)', files => ["$file"] );
+    my %content = ( comment => '(See attachments)', files => ["$file"] );
     $ticket->update(%content);
     return $ticket_id;
 }
@@ -136,8 +162,18 @@ sub _recode_props_for_integrate {
     my %attr;
 
     for my $key ( keys %props ) {
-        next unless ( $key =~ /^(summary|status|owner)/ );
-        $attr{$key} = $props{$key};
+        if ( $key =~ /^(summary|status|owner|cc)/ ) {
+            $attr{$key} = $props{$key};
+        }
+        elsif ( $key eq 'tags' ) {
+            $attr{labels} ||= [];
+            push @{$attr{labels}}, split /\s*,\s*/, $props{$key};
+        }
+        else {
+            $attr{labels} ||= [];
+            push @{ $attr{labels} },
+              ( ucfirst $key ) . '-' . ucfirst $props{$key};
+        }
     }
     return \%attr;
 }

commit bdb68aeffe760120fc63b1322febd2e1cdf69852
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed May 27 11:26:27 2009 +0800

    sign in stuff for gcode push

diff --git a/lib/App/SD/Replica/gcode/PushEncoder.pm b/lib/App/SD/Replica/gcode/PushEncoder.pm
index 247a6ac..f8c5548 100644
--- a/lib/App/SD/Replica/gcode/PushEncoder.pm
+++ b/lib/App/SD/Replica/gcode/PushEncoder.pm
@@ -9,7 +9,6 @@ has sync_source => (
     isa => 'App::SD::Replica::gcode',
     is  => 'rw',
 );
-my $gcode;
 
 sub integrate_change {
     my $self = shift;
@@ -31,9 +30,13 @@ sub integrate_change {
         $changeset->original_source_uuid ) >= $changeset->original_sequence_no;
 
     my $before_integration = time();
-    $gcode ||= Net::Google::Code->new(
-        project  => $self->sync_source->project,
-    );
+    my ( $email, $password );
+    if ( !$self->sync_source->gcode->password ) {
+        ( $email, $password ) = $self->sync_source->prompt_for_login(
+            'gcode:' . $self->sync_source->project );
+        $self->sync_source->gcode->email($email);
+        $self->sync_source->gcode->password($password);
+    }
 
     eval {
         if (    $change->record_type eq 'ticket'
@@ -89,7 +92,7 @@ sub integrate_ticket_update {
     # Figure out the remote site's ticket ID for this change's record
     my $remote_ticket_id =
       $self->sync_source->remote_id_for_uuid( $change->record_uuid );
-    my $ticket = $gcode->issue();
+    my $ticket = $self->sync_source->gcode->issue();
     $ticket->load($remote_ticket_id);
     $ticket->update( %{ $self->_recode_props_for_integrate($change) }, );
     return $remote_ticket_id;
@@ -104,7 +107,7 @@ sub integrate_ticket_create {
     );
 
     # Build up a ticket object out of all the record's attributes
-    my $ticket = $gcode->issue;
+    my $ticket = $self->sync_source->gcode->issue;
     my $id =
       $ticket->create( %{ $self->_recode_props_for_integrate($change) } );
 
@@ -124,7 +127,7 @@ sub integrate_comment {
     my %props = map { $_->name => $_->new_value } $change->prop_changes;
 
     my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
-    my $ticket = $gcode->issue( id => $ticket_id );
+    my $ticket = $self->sync_source->gcode->issue( id => $ticket_id );
 
     my %content = ( comment => $props{'content'}, );
 
@@ -142,7 +145,7 @@ sub integrate_attachment {
 
     my %props     = map { $_->name => $_->new_value } $change->prop_changes;
     my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
-    my $ticket    = $gcode->issue( id => $ticket_id, );
+    my $ticket    = $self->sync_source->gcode->issue( id => $ticket_id, );
 
     my $tempdir = File::Temp::tempdir( CLEANUP => 1 );
     my $file = file( $tempdir => ( $props{'name'} || 'unnamed' ) );

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



More information about the Bps-public-commit mailing list