[Bps-public-commit] SD branch, master, updated. 1e1a24145a29f17e9c237089ad64a5561055f5ca
jesse
jesse at bestpractical.com
Tue Apr 21 10:57:53 EDT 2009
The branch, master has been updated
via 1e1a24145a29f17e9c237089ad64a5561055f5ca (commit)
via 8c943173fa41d952f2592b897ade584e33bd6b8f (commit)
via 77ed346a2630984c32552672612c7795a6f4f12a (commit)
via b8d8e2988d888831dcaee3159fef2cb7159caaa6 (commit)
via 0be7a99b0f532b63586169a63ac11f429fd88440 (commit)
via d99e1ebf1d26756c7a246f4c760ce2c6e9f325a1 (commit)
via b8fedc83507ff531fff0d3ac2436e8ba8518fde4 (commit)
via 685f79afd2b10da910e4e8a08cb7a7bad8f2342f (commit)
via 9c23280fa6515b37925c47df1c75f9aba4af80a6 (commit)
from 6135b51a3fcda1d6ed514f7fe370c5a159be9c21 (commit)
Summary of changes:
lib/App/SD/ForeignReplica.pm | 31 ++++++++--------
lib/App/SD/Replica/github.pm | 63 ++++++++++++++++++++++++++++++++
lib/App/SD/Replica/rt.pm | 5 ---
lib/App/SD/Replica/rt/PullEncoder.pm | 41 ++++++++++-----------
lib/App/SD/Replica/trac.pm | 7 ++--
lib/App/SD/Replica/trac/PullEncoder.pm | 15 +++++---
lib/App/SD/Replica/trac/PushEncoder.pm | 37 +++++++++++--------
t/sd-trac/basic.t | 28 ++++++++++++++-
8 files changed, 160 insertions(+), 67 deletions(-)
create mode 100644 lib/App/SD/Replica/github.pm
- Log -----------------------------------------------------------------
commit 9c23280fa6515b37925c47df1c75f9aba4af80a6
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Apr 20 16:07:15 2009 +0800
Failing test for push to trac
diff --git a/t/sd-trac/basic.t b/t/sd-trac/basic.t
index da886ef..5add180 100644
--- a/t/sd-trac/basic.t
+++ b/t/sd-trac/basic.t
@@ -75,5 +75,28 @@ run_output_matches('sd',
[qr/(.*?)(?{ $pony_id = $1 }) The product does not contain a pony new/]
);
+ok($pony_id, "I got the ID of a pony - It's $pony_id");
+
+($ret,$out,$err) = run_script('sd', ["ticket", "update", $pony_id ,"--", "status=closed"]);
+like($out, qr/^Ticket(.*)updated/);
+diag($out);
+diag($err);
+($ret,$out,$err) = run_script('sd' => ["ticket" ,"basics" ,$pony_id ,"--batch"]);
+
+like($out, qr/status: closed/);
diag("The pony is $pony_id");
+my $new_ticket = Net::Trac::Ticket->new( connection => $trac);
+isa_ok($new_ticket, 'Net::Trac::Ticket');
+ok($new_ticket->load(1));
+is($new_ticket->status, 'new', "The ticket is new before we push to trac");
+
+( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_trac_url ] );
+diag($out);
+diag($err);
+
+
+ok($new_ticket->load(1));
+is($new_ticket->status, 'closed', "The ticket is closed after we push to trac");
+
+
commit 685f79afd2b10da910e4e8a08cb7a7bad8f2342f
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Apr 20 16:53:21 2009 +0800
Perltidy
diff --git a/lib/App/SD/ForeignReplica.pm b/lib/App/SD/ForeignReplica.pm
index 6d5f2bb..cf9474d 100644
--- a/lib/App/SD/ForeignReplica.pm
+++ b/lib/App/SD/ForeignReplica.pm
@@ -4,7 +4,6 @@ use Params::Validate;
extends 'Prophet::ForeignReplica';
-
=head2 integrate_change $change $changeset
Given a change (and the changeset it's part of), this routine will load
@@ -34,11 +33,10 @@ sub integrate_change {
$recoder->integrate_change($change,$changeset);
}
-
-
=head2 record_pushed_transaction $foreign_transaction_id, $changeset
-Record that this replica was the original source of $foreign_transaction_id (with changeset $changeset)
+Record that this replica was the original source of $foreign_transaction_id
+(with changeset $changeset)
=cut
@@ -48,8 +46,11 @@ sub record_pushed_transaction {
{ transaction => 1, changeset => { isa => 'Prophet::ChangeSet' }, record => 1 } );
$self->store_local_metadata(
- "foreign-txn-from-".$self->uuid . '-record-'.$args{record}. '-txn-' . $args{transaction} =>
- join( ':',
+ "foreign-txn-from-"
+ . $self->uuid
+ . '-record-'
+ . $args{record} . '-txn-'
+ . $args{transaction} => join( ':',
$args{changeset}->original_source_uuid,
$args{changeset}->original_sequence_no )
);
@@ -57,8 +58,10 @@ sub record_pushed_transaction {
=head2 foreign_transaction_originated_locally $transaction_id $foreign_record_id
-Given a transaction id, will return true if this transaction originated in Prophet
-and was pushed to RT or originated in RT and has already been pulled to the prophet replica.
+Given a transaction id, will return true if this transaction
+originated in Prophet and was pushed to the foreign replica or
+originated in the foreign replica and has already been pulled to
+the Prophet replica.
This is a mapping of all the transactions we have pushed to the
@@ -75,8 +78,9 @@ remote replica when doing a subsequent pull
sub foreign_transaction_originated_locally {
my $self = shift;
- my ($id, $record) = validate_pos( @_, 1, 1);
- return $self->fetch_local_metadata("foreign-txn-from-". $self->uuid .'-record-'.$record. '-txn-' .$id );
+ my ( $id, $record ) = validate_pos( @_, 1, 1 );
+ return $self->fetch_local_metadata(
+ "foreign-txn-from-" . $self->uuid . '-record-' . $record . '-txn-' . $id );
}
sub traverse_changesets {
@@ -94,7 +98,8 @@ sub traverse_changesets {
}
sub remote_uri_path_for_id {
- die "your subclass needds to implement this to be able to map a remote id to /ticket/id or soemthing";
+ die "your subclass needds to implement this to be able to ".
+ "map a remote id to /ticket/id or soemthing";
}
@@ -105,11 +110,9 @@ construct it out of the remote url and the remote uri path for the record id;
=cut
-
sub uuid_for_remote_id {
my ( $self, $id ) = @_;
-
return $self->_lookup_uuid_for_remote_id($id)
|| $self->uuid_for_url( $self->remote_url . $self->remote_uri_path_for_id($id) );
}
@@ -181,7 +184,6 @@ sub _set_remote_id_for_uuid {
}
-
=head2 record_remote_id_for_pushed_record
When pushing a record created within the prophet cloud to a foreign replica, we
@@ -189,7 +191,6 @@ need to do bookkeeping to record the prophet uuid to remote id mapping.
=cut
-
sub record_remote_id_for_pushed_record {
my $self = shift;
my %args = validate(
commit b8fedc83507ff531fff0d3ac2436e8ba8518fde4
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Apr 20 19:13:44 2009 +0800
Perltidy
diff --git a/lib/App/SD/Replica/rt/PullEncoder.pm b/lib/App/SD/Replica/rt/PullEncoder.pm
index 8d7351f..2426bf5 100644
--- a/lib/App/SD/Replica/rt/PullEncoder.pm
+++ b/lib/App/SD/Replica/rt/PullEncoder.pm
@@ -20,54 +20,52 @@ sub run {
}
);
-
my $tickets = {};
my @transactions;
- my @tickets = $self->find_matching_tickets( $self->sync_source->rt_query );
+ my @tickets = $self->find_matching_tickets( $self->sync_source->rt_query );
$self->sync_source->log("No tickets found.") if @tickets == 0;
my $counter = 0;
$self->sync_source->log("Discovering ticket history");
- my ($last_modified, $last_txn);
+ my ( $last_modified, $last_txn );
my $progress = Time::Progress->new();
$progress->attr( max => $#tickets );
local $| = 1;
-
for my $id (@tickets) {
$counter++;
print $progress->report( "%30b %p Est: %E\r", $counter );
- $self->sync_source->log( "Fetching ticket $id - $counter of " . scalar @tickets);
+ $self->sync_source->log( "Fetching ticket $id - $counter of " . scalar @tickets );
- $tickets->{ $id } = $self->_translate_final_ticket_state(
- $self->sync_source->rt->show( type => 'ticket', id => $id )
- );
+ $tickets->{$id} = $self->_translate_final_ticket_state(
+ $self->sync_source->rt->show( type => 'ticket', id => $id ) );
push @transactions, @{
$self->find_matching_transactions(
ticket => $id,
- starting_transaction => (( $args{'after'} + 1 ) || 1)
+ starting_transaction => ( ( $args{'after'} + 1 ) || 1 )
)
- };
+ };
}
my $txn_counter = 0;
my @changesets;
for my $txn ( sort { $b->{'id'} <=> $a->{'id'} } @transactions ) {
- my $created = App::SD::Util::string_to_datetime($txn->{Created});
+ my $created = App::SD::Util::string_to_datetime( $txn->{Created} );
- $last_modified = $created if ( !$last_modified || ($created > $last_modified ));
- $last_txn = $txn->{'id'} if (!$last_txn || ($txn->{id} > $last_txn));
+ $last_modified = $created if ( !$last_modified || ( $created > $last_modified ) );
+ $last_txn = $txn->{'id'} if ( !$last_txn || ( $txn->{id} > $last_txn ) );
$txn_counter++;
- $self->sync_source->log("Transcoding transaction @{[$txn->{'id'}]} - $txn_counter of ". scalar @transactions);
+ $self->sync_source->log( "Transcoding transaction @{[$txn->{'id'}]} - $txn_counter of "
+ . scalar @transactions );
my $changeset = $self->transcode_one_txn( $txn, $tickets->{ $txn->{Ticket} } );
$changeset->created( $txn->{'Created'} );
next unless $changeset->has_changes;
@@ -75,20 +73,21 @@ sub run {
}
my $cs_counter = 0;
- for ( @changesets ) {
- $self->sync_source->log("Applying changeset ".++$cs_counter . " of ".scalar @changesets);
- $args{callback}->($_)
+ for (@changesets) {
+ $self->sync_source->log(
+ "Applying changeset " . ++$cs_counter . " of " . scalar @changesets );
+ $args{callback}->($_);
}
- my $last_modified_datetime = App::SD::Util::string_to_datetime($self->sync_source->upstream_last_modified_date);
+ my $last_modified_datetime
+ = App::SD::Util::string_to_datetime( $self->sync_source->upstream_last_modified_date );
$self->sync_source->record_upstream_last_modified_date($last_modified)
if ( ( $last_modified ? $last_modified->epoch : 0 )
- > ( $last_modified_datetime ? $last_modified_datetime->epoch : 0 ) );
+ > ( $last_modified_datetime ? $last_modified_datetime->epoch : 0 ) );
$self->sync_source->record_upstream_last_txn($last_txn)
if ( ( $last_txn || 0 ) > ( $self->sync_source->upstream_last_txn || 0 ) );
}
-
sub _translate_final_ticket_state {
my $self = shift;
my $ticket = shift;
@@ -517,8 +516,6 @@ sub resolve_user_id_to {
memoize 'resolve_user_id_to';
-
-
our %PROP_MAP = (
subject => 'summary',
status => 'status',
commit d99e1ebf1d26756c7a246f4c760ce2c6e9f325a1
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Apr 20 19:14:01 2009 +0800
Perltidy
diff --git a/lib/App/SD/Replica/rt.pm b/lib/App/SD/Replica/rt.pm
index acaa9ef..636a104 100644
--- a/lib/App/SD/Replica/rt.pm
+++ b/lib/App/SD/Replica/rt.pm
@@ -103,7 +103,6 @@ sub record_pushed_transactions {
}
}
-
sub record_upstream_last_modified_date {
my $self = shift;
my $date = shift;
@@ -126,8 +125,6 @@ sub record_upstream_last_txn {
return $self->store_local_metadata('last_txn_id' => $id);
}
-
-
=head2 uuid
Return the replica's UUID
@@ -140,14 +137,12 @@ sub uuid {
}
-
sub remote_uri_path_for_id {
my $self = shift;
my $id = shift;
return "/ticket/".$id;
}
-
=head1 NOTES ON PUSH
If the remote storage (RT) can not represent a whole changeset along with the prophet changeset uuid, then we need to
commit 0be7a99b0f532b63586169a63ac11f429fd88440
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Apr 20 19:14:09 2009 +0800
failing tests for push a status update to trac
diff --git a/t/sd-trac/basic.t b/t/sd-trac/basic.t
index 5add180..df97d8d 100644
--- a/t/sd-trac/basic.t
+++ b/t/sd-trac/basic.t
@@ -15,7 +15,7 @@ BEGIN {
unless (`which trac-admin`) { plan skip_all => 'You need trac installed to run the tests'; }
unless (eval { require Net::Trac} ) { plan skip_all => 'You need Net::Trac installed to run the tests'; }
-plan tests => 18;
+plan tests => 25;
use_ok('Net::Trac::Connection');
@@ -87,7 +87,6 @@ like($out, qr/status: closed/);
diag("The pony is $pony_id");
my $new_ticket = Net::Trac::Ticket->new( connection => $trac);
-isa_ok($new_ticket, 'Net::Trac::Ticket');
ok($new_ticket->load(1));
is($new_ticket->status, 'new', "The ticket is new before we push to trac");
@@ -96,7 +95,11 @@ diag($out);
diag($err);
-ok($new_ticket->load(1));
-is($new_ticket->status, 'closed', "The ticket is closed after we push to trac");
+my $closed_ticket = Net::Trac::Ticket->new( connection => $trac);
+ok($closed_ticket->load(1));
+is($closed_ticket->status, 'resolved', "The ticket is closed after we push to trac");
+( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_trac_url ] );
+diag($out);
+diag($err);
commit b8d8e2988d888831dcaee3159fef2cb7159caaa6
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Apr 20 19:15:24 2009 +0800
perltidy
diff --git a/lib/App/SD/Replica/trac/PullEncoder.pm b/lib/App/SD/Replica/trac/PullEncoder.pm
index 6632c2c..d24a613 100644
--- a/lib/App/SD/Replica/trac/PullEncoder.pm
+++ b/lib/App/SD/Replica/trac/PullEncoder.pm
@@ -39,11 +39,13 @@ sub run {
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 );
+ $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);
+ $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_data = $self->_translate_final_ticket_state($ticket);
my $ticket_initial_data = {%$ticket_data};
my $txns = $self->skip_previously_seen_transactions(
ticket => $ticket,
@@ -53,8 +55,10 @@ sub run {
# 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 );
+ unshift @changesets,
+ grep {defined} $self->transcode_one_txn( $txn, $ticket_initial_data, $ticket_data );
}
# create is oldest of all
@@ -63,7 +67,7 @@ sub run {
$self->_record_upstream_last_modified_date($last_modified_date);
- $args{callback}->($_) for @changesets;
+ $args{callback}->($_) for @changesets;
}
sub _record_upstream_last_modified_date {
@@ -72,7 +76,6 @@ sub _record_upstream_last_modified_date {
return $self->sync_source->store_local_metadata('last_changeset_date' => $date);
}
-
sub _translate_final_ticket_state {
my $self = shift;
my $ticket_object = shift;
commit 77ed346a2630984c32552672612c7795a6f4f12a
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Apr 20 19:15:48 2009 +0800
comment out the trac pushed transaction walker cloned from an earlier version of the RT replica
diff --git a/lib/App/SD/Replica/trac.pm b/lib/App/SD/Replica/trac.pm
index a1e509e..c29f1f2 100644
--- a/lib/App/SD/Replica/trac.pm
+++ b/lib/App/SD/Replica/trac.pm
@@ -52,15 +52,16 @@ sub record_pushed_transactions {
{ ticket => 1, changeset => { isa => 'Prophet::ChangeSet' } } );
# walk through every transaction on the ticket, starting with the latest
- for my $txn ( 'find all the transactions pushed upstream') {
-
+ warn "need to walk the pushed txns";
+ for my $txn ( undef ){# 'find all the transactions pushed upstream') {
+ last;
# 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->last_changeset_from_source(
$args{changeset}->original_source_uuid
);
- # if the transaction from RT is more recent than the most recent
+ # if the transaction from Trac is more recent than the most recent
# transaction we got from the original source of the changeset
# then we should record that we sent that transaction upstream
# XXX TODO - THIS IS WRONG - we should only be recording transactions we pushed
commit 8c943173fa41d952f2592b897ade584e33bd6b8f
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Apr 20 19:17:52 2009 +0800
First pass at a basic push encoder which sends can close a ticket in trac
diff --git a/lib/App/SD/Replica/trac/PushEncoder.pm b/lib/App/SD/Replica/trac/PushEncoder.pm
index 3b7144b..1e769fa 100644
--- a/lib/App/SD/Replica/trac/PushEncoder.pm
+++ b/lib/App/SD/Replica/trac/PushEncoder.pm
@@ -2,6 +2,8 @@ package App::SD::Replica::trac::PushEncoder;
use Any::Moose;
use Params::Validate;
use Path::Class;
+use Time::HiRes qw/usleep/;
+
has sync_source =>
( isa => 'App::SD::Replica::trac',
is => 'rw');
@@ -15,7 +17,13 @@ sub integrate_change {
{ isa => 'Prophet::ChangeSet' }
);
my $id;
- local $@;
+ my $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
+ return if $self->sync_source->app_handle->handle->last_changeset_from_source( $changeset->original_source_uuid) >= $changeset->original_sequence_no;
+
eval {
if ( $change->record_type eq 'ticket'
and $change->change_type eq 'add_file' )
@@ -45,6 +53,7 @@ sub integrate_change {
}
else {
+ $self->sync_source->log('I have no idea what I am doing for '.$change->record_uuid);
return undef;
}
@@ -54,7 +63,12 @@ sub integrate_change {
);
};
- warn $@ if $@;
+ if (my $err = $@) {
+ $self->sync_source->log("Push error: ".$err);
+ }
+
+ usleep(1100); # trac only accepts one ticket update per second. Yes.
+
return $id;
}
@@ -69,12 +83,9 @@ 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 = Net::Trac::Ticket->new(
- trac => $self->sync_source->trac,
- id => $remote_ticket_id,
- %{ $self->_recode_props_for_integrate($change) }
- )->store();
-
+ my $ticket = Net::Trac::Ticket->new( connection => $self->sync_source->trac);
+ $ticket->load($remote_ticket_id);
+ $ticket->update( %{ $self->_recode_props_for_integrate($change) }, no_auto_status => 1);
return $remote_ticket_id;
}
@@ -88,12 +99,10 @@ sub integrate_ticket_create {
# Build up a ticket object out of all the record's attributes
my $ticket = Net::Trac::Ticket->new(
- trac => $self->sync_source->trac,
- queue => $self->sync_source->trac_queue(),
- %{ $self->_recode_props_for_integrate($change) }
- )->store( text => "Not yet pulling in ticket creation comment" );
+ connection => $self->sync_source->trac);
+ my $id = $ticket->create( %{ $self->_recode_props_for_integrate($change) });
- return $ticket->id;
+ return $id
}
sub integrate_comment {
@@ -148,8 +157,6 @@ sub _recode_props_for_integrate {
next unless ( $key =~ /^(summary|queue|status|owner|custom)/ );
if ( $key =~ /^custom-(.*)/ ) {
$attr{cf}->{$1} = $props{$key};
- } elsif ( $key eq 'summary' ) {
- $attr{'subject'} = $props{summary};
} else {
$attr{$key} = $props{$key};
}
commit 1e1a24145a29f17e9c237089ad64a5561055f5ca
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Tue Apr 21 23:57:32 2009 +0900
Beginning of a sketch of the github replica type From c9s++
diff --git a/lib/App/SD/Replica/github.pm b/lib/App/SD/Replica/github.pm
new file mode 100644
index 0000000..5d5fe0a
--- /dev/null
+++ b/lib/App/SD/Replica/github.pm
@@ -0,0 +1,63 @@
+package App::SD::Replica::github;
+use Any::Moose;
+extends qw/App::SD::ForeignReplica/;
+
+use Params::Validate qw(:all);
+use Memoize;
+
+use UNIVERSAL::require;
+use URI;
+use Memoize;
+use Net::Github;
+
+use Prophet::ChangeSet;
+
+use constant scheme => 'github';
+use constant pull_encoder => 'App::SD::Replica::github::PullEncoder';
+use constant push_encoder => 'App::SD::Replica::github::PushEncoder';
+
+has github => ( isa => 'Net::Github', is => 'rw' );
+has remote_url => ( isa => 'Str', is => 'rw' );
+has owner => ( isa => 'Str', is => 'rw' );
+has repo => ( isa => 'Str', is => 'rw' );
+
+sub BUILD {
+ my $self = shift;
+
+ my ( $server , $owner , $repo ) = $self->{url} =~ m/^github:(.+?)\|(\w+)\|(\w+)\|$/
+ or die "Can't parse Github server spec. Expected github:http://user\@github.com|owner|repository|";
+
+
+ my $uri = URI->new($server);
+ my ( $username, $apikey );
+ if ( my $auth = $uri->userinfo ) {
+ ( $username, $apikey ) = split /:/, $auth, 2;
+ $uri->userinfo(undef);
+ }
+
+ ( $username, $apikey ) = $self->prompt_for_login( $uri, $username ) unless $apikey ;
+
+ $self->remote_url("$uri");
+ $self->owner( $owner );
+ $self->repo( $repo );
+
+ $self->github(
+ Net::GitHub->new(
+ login => $username,
+ token => $apikey,
+ repo => $repo,
+ owner => $owner,
+ ) );
+}
+
+sub record_pushed_transactions {}
+
+sub uuid {
+ my $self = shift;
+ Carp::cluck "- can't make a uuid for this" unless ($self->remote_url && $self->owner && $self->repo );
+ return $self->uuid_for_url( join( '/', $self->remote_url, $self->owner , $self->repo ) );
+}
+
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+1;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list