[Bps-public-commit] SD branch, master, updated. 0.73-10-g6f6d231

jesse jesse at bestpractical.com
Wed Sep 16 16:11:25 EDT 2009


The branch, master has been updated
       via  6f6d231fc7adb368c36b04ce9312e4cf0bf97671 (commit)
       via  0a6b5225a76a875c198b4829db443e91c9b3f5eb (commit)
       via  fa39770485fe48ef3d8c22ec0a46ce93de4eb4ce (commit)
       via  04b6eaa47d1c6b8cad57b6681a934f41b2f2ccbc (commit)
       via  99a438df879476209cb732004e8664a3d41f63a1 (commit)
       via  bd07bb5f13e50f36eff1b06154da26870ae35bc5 (commit)
      from  93b1d22638b8852f858e8b9787ce734b0fe1d9e0 (commit)

Summary of changes:
 lib/App/SD/Replica/redmine.pm             |    3 +
 lib/App/SD/Replica/redmine/PushEncoder.pm |  145 +++++++++++++++++++++++++++++
 t/sd-redmine/basic.t                      |    8 +-
 3 files changed, 150 insertions(+), 6 deletions(-)

- Log -----------------------------------------------------------------
commit bd07bb5f13e50f36eff1b06154da26870ae35bc5
Author: franck cuny <franck at lumberjaph.net>
Date:   Mon Sep 14 17:18:28 2009 +0200

    push new ticket

diff --git a/lib/App/SD/Replica/redmine.pm b/lib/App/SD/Replica/redmine.pm
index f31bc37..910ca11 100644
--- a/lib/App/SD/Replica/redmine.pm
+++ b/lib/App/SD/Replica/redmine.pm
@@ -1,5 +1,9 @@
 package App::SD::Replica::redmine;
 use Any::Moose;
+
+# XXX
+use YAML::Syck;
+
 extends 'App::SD::ForeignReplica';
 
 use constant scheme => 'redmine';
@@ -45,6 +49,8 @@ sub BUILD {
 
 }
 
+sub record_pushed_transactions {}
+
 sub uuid {
     my $self = shift;
     Carp::cluck "- can't make a uuid for this" unless ($self->remote_url);
diff --git a/lib/App/SD/Replica/redmine/PushEncoder.pm b/lib/App/SD/Replica/redmine/PushEncoder.pm
index 512bc8a..d2c7feb 100644
--- a/lib/App/SD/Replica/redmine/PushEncoder.pm
+++ b/lib/App/SD/Replica/redmine/PushEncoder.pm
@@ -1,3 +1,117 @@
 package App::SD::Replica::redmine::PushEncoder;
 
+use Any::Moose;
+use Params::Validate;
+use YAML::Syck;
+
+has sync_source => (
+    isa => 'App::SD::Replica::redmine',
+    is  => 'rw',
+    required => 1
+);
+
+sub integrate_change {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+    my ( $id, $record );
+
+    return
+      if $self->sync_source->app_handle->handle->last_changeset_from_source(
+        $changeset->original_source_uuid ) >= $changeset->original_sequence_no;
+
+    my $before_integration = time();
+
+    eval {
+        if (    $change->record_type eq 'ticket'
+            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,
+            );
+        }
+        elsif ( $change->record_type eq 'comment'
+            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;
+        }
+
+        $self->sync_source->record_pushed_transactions(
+            start_time => $before_integration,
+            ticket     => $id,
+            changeset  => $changeset,
+        );
+    };
+
+    if ( my $err = $@ ) {
+        $self->sync_source->log( "Push error: " . $err );
+    }
+
+    return $id;
+}
+
+sub integrate_ticket_update {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+}
+
+sub integrate_ticket_create {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+    my $attr = $self->_recode_props_for_integrate($change);
+    my $ticket = $self->sync_source->redmine->create(ticket => $attr);
+    # TODO error
+    return $new->{id};
+}
+
+sub integrate_comment {
+    my $self = shift;
+    my ($change) = validate_pos( @_, { isa => 'Prophet::Change' } );
+}
+
+sub _recode_props_for_integrate {
+    my $self = shift;
+    my ($change) = validate_pos( @_, { isa => 'Prophet::Change' } );
+
+    my %props = map { $_->name => $_->new_value } $change->prop_changes;
+    my %attr;
+
+    # TODO fixme
+    for my $key ( keys %props ) {
+        if ( $key eq 'summary' ) {
+            $attr{subject} = $props{$key};
+        }
+        elsif ( $key eq 'body' ) {
+            $attr{description} = $props{$key};
+        }
+        elsif ( $key eq 'status' ) {
+            $attr{state} = $props{$key} =~ /new|open/ ? 'open' : 'closed';
+        }
+    }
+    return \%attr;
+}
+
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
 1;

commit 99a438df879476209cb732004e8664a3d41f63a1
Author: franck cuny <franck at lumberjaph.net>
Date:   Tue Sep 15 15:26:59 2009 +0200

    integrate comment and update

diff --git a/lib/App/SD/Replica/redmine/PushEncoder.pm b/lib/App/SD/Replica/redmine/PushEncoder.pm
index d2c7feb..ac462f1 100644
--- a/lib/App/SD/Replica/redmine/PushEncoder.pm
+++ b/lib/App/SD/Replica/redmine/PushEncoder.pm
@@ -70,6 +70,23 @@ sub integrate_ticket_update {
         { isa => 'Prophet::Change' },
         { isa => 'Prophet::ChangeSet' }
     );
+    my $remote_ticket_id
+        = $self->sync_source->remote_id_for_uuid( $change->record_uuid );
+    my $attr = $self->_recode_props_for_integrate($change);
+
+    my $ticket = Net::Redmine::Ticket->load(
+        connection => $self->sync_source->redmine->connection,
+        id         => $remote_ticket_id
+    );
+    for (qw/subject description /) {
+        $ticket->$_( $attr->{$_} ) if $attr->{$_};
+    }
+    if ( $attr->{state} ) {
+        $ticket->status("Open")  if $attr->{state} eq 'open';
+        $ticket->status("Closed") if $attr->{state} eq 'closed';
+    }
+    $ticket->save;
+    return $remote_ticket_id;
 }
 
 sub integrate_ticket_create {
@@ -82,12 +99,27 @@ sub integrate_ticket_create {
     my $attr = $self->_recode_props_for_integrate($change);
     my $ticket = $self->sync_source->redmine->create(ticket => $attr);
     # TODO error
-    return $new->{id};
+    return $ticket->{id};
 }
 
 sub integrate_comment {
     my $self = shift;
-    my ($change) = validate_pos( @_, { isa => 'Prophet::Change' } );
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+
+    my %props = map { $_->name => $_->new_value } $change->prop_changes;
+    my $ticket_id
+        = $self->sync_source->remote_id_for_uuid( $props{'ticket'} );
+    my $ticket = Net::Redmine::Ticket->load(
+        connection => $self->sync_source->redmine->connection,
+        id         => $ticket_id
+    );
+    $ticket->description( $props{'content'} );
+    $ticket->save;
+    return $ticket_id;
 }
 
 sub _recode_props_for_integrate {
@@ -114,4 +146,5 @@ sub _recode_props_for_integrate {
 
 __PACKAGE__->meta->make_immutable;
 no Any::Moose;
+
 1;

commit 04b6eaa47d1c6b8cad57b6681a934f41b2f2ccbc
Author: franck cuny <franck at lumberjaph.net>
Date:   Tue Sep 15 15:35:10 2009 +0200

    update tests

diff --git a/t/sd-redmine/basic.t b/t/sd-redmine/basic.t
index 77a5fb7..aab3663 100644
--- a/t/sd-redmine/basic.t
+++ b/t/sd-redmine/basic.t
@@ -20,7 +20,7 @@ require 't/sd-redmine/net_redmine_test.pl';
 
 my $r = new_redmine();
 
-plan tests => 1;
+plan tests => 2;
 
 note "create 5 new tickets in redmine.";
 my @tickets = new_tickets($r, 5);
@@ -53,11 +53,7 @@ diag($err);
 note "verify the update with Net::Redmine";
 my $ticket = $r->lookup(ticket => { id => $tickets[0]->id });
 
-TODO: {
-    local $TODO = 'write support is not yet implemented';
-
-    is($ticket->status, "Closed");
-};
+is($ticket->status, "Closed");
 
 ##
 sub count_tickets_in_sd {

commit fa39770485fe48ef3d8c22ec0a46ce93de4eb4ce
Author: franck cuny <franck at lumberjaph.net>
Date:   Tue Sep 15 15:49:37 2009 +0200

    -fixme

diff --git a/lib/App/SD/Replica/redmine/PushEncoder.pm b/lib/App/SD/Replica/redmine/PushEncoder.pm
index ac462f1..09373d8 100644
--- a/lib/App/SD/Replica/redmine/PushEncoder.pm
+++ b/lib/App/SD/Replica/redmine/PushEncoder.pm
@@ -129,7 +129,6 @@ sub _recode_props_for_integrate {
     my %props = map { $_->name => $_->new_value } $change->prop_changes;
     my %attr;
 
-    # TODO fixme
     for my $key ( keys %props ) {
         if ( $key eq 'summary' ) {
             $attr{subject} = $props{$key};

commit 0a6b5225a76a875c198b4829db443e91c9b3f5eb
Merge: 93b1d22 fa39770
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Wed Sep 16 01:43:08 2009 +0900

    Merge commit 'franckcuny/redmine'
    
    * commit 'franckcuny/redmine':
      -fixme
      update tests
      integrate comment and update
      push new ticket


commit 6f6d231fc7adb368c36b04ce9312e4cf0bf97671
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Wed Sep 16 01:45:45 2009 +0900

    Remove "use YAML::Syck" which seems to be a vestige of debugging code

diff --git a/lib/App/SD/Replica/redmine.pm b/lib/App/SD/Replica/redmine.pm
index 910ca11..f04eee1 100644
--- a/lib/App/SD/Replica/redmine.pm
+++ b/lib/App/SD/Replica/redmine.pm
@@ -1,9 +1,6 @@
 package App::SD::Replica::redmine;
 use Any::Moose;
 
-# XXX
-use YAML::Syck;
-
 extends 'App::SD::ForeignReplica';
 
 use constant scheme => 'redmine';
diff --git a/lib/App/SD/Replica/redmine/PushEncoder.pm b/lib/App/SD/Replica/redmine/PushEncoder.pm
index 09373d8..8d2dbfb 100644
--- a/lib/App/SD/Replica/redmine/PushEncoder.pm
+++ b/lib/App/SD/Replica/redmine/PushEncoder.pm
@@ -2,7 +2,6 @@ package App::SD::Replica::redmine::PushEncoder;
 
 use Any::Moose;
 use Params::Validate;
-use YAML::Syck;
 
 has sync_source => (
     isa => 'App::SD::Replica::redmine',

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



More information about the Bps-public-commit mailing list