[Bps-public-commit] r15064 - in sd/trunk: . bin lib/App/SD/Model lib/App/SD/Replica/Hiveminder lib/App/SD/Replica/RT t

spang at bestpractical.com spang at bestpractical.com
Tue Aug 12 08:55:19 EDT 2008


Author: spang
Date: Tue Aug 12 08:55:10 2008
New Revision: 15064

Modified:
   sd/trunk/   (props changed)
   sd/trunk/Makefile.PL
   sd/trunk/bin/sd
   sd/trunk/lib/App/SD/Model/Attachment.pm
   sd/trunk/lib/App/SD/Model/Ticket.pm
   sd/trunk/lib/App/SD/Replica/Hiveminder.pm
   sd/trunk/lib/App/SD/Replica/Hiveminder/PullEncoder.pm
   sd/trunk/lib/App/SD/Replica/RT.pm
   sd/trunk/lib/App/SD/Replica/RT/PullEncoder.pm
   sd/trunk/t/attachment-content.t
   sd/trunk/t/sd-attachments.t
   sd/trunk/t/sd-rt.t

Log:
 r43759 at loki:  spang | 2008-07-08 16:47:46 +0100
  r43524 at loki (orig r13728):  jesse | 2008-07-02 17:06:16 +0100
   r39107 at 31b:  jesse | 2008-07-02 12:02:36 +0300
   * Significant moosing of the SD commandline. It almost works. But not quite.
   * SD now only works with a moosed prophet
   * Moose is the future. The future is Now (2 July 2008)
   
       - Topkapi Palace - 2 July 2008
   
  
  r43551 at loki (orig r13751):  jesse | 2008-07-03 07:53:31 +0100
   Small, moosy bug fixes
  r43637 at loki (orig r13797):  jesse | 2008-07-04 11:37:26 +0100
   * more work to start passing tests
  r43641 at loki (orig r13801):  sartak | 2008-07-04 12:06:18 +0100
   r63712 at onn:  sartak | 2008-07-04 07:06:05 -0400
   Move run_one_command to the bottom of bin/sd, after all of Moose's runtime sugar is run
  
  r43672 at loki (orig r13806):  jesse | 2008-07-04 14:33:21 +0100
  * fewer failing tests.
  r43673 at loki (orig r13807):  jesse | 2008-07-04 14:50:47 +0100
  * more sd moose cleanup
  r43674 at loki (orig r13808):  clkao | 2008-07-04 15:30:13 +0100
  restore the setup behaviour for hm replica.
  
  r43675 at loki (orig r13809):  clkao | 2008-07-04 15:40:04 +0100
  * is_empty is now !has_changes.
  * fix the setup logic for rt replica as well.
  
  r43676 at loki (orig r13810):  jesse | 2008-07-04 16:18:02 +0100
  * removing some warnings
  r43677 at loki (orig r13811):  jesse | 2008-07-04 16:19:14 +0100
  Moosification
  r43678 at loki (orig r13812):  jesse | 2008-07-04 16:22:29 +0100
  * back down to one failing test in sd-rt
  r43682 at loki (orig r13814):  jesse | 2008-07-05 11:32:59 +0100
   tests all pass
 


Modified: sd/trunk/Makefile.PL
==============================================================================
--- sd/trunk/Makefile.PL	(original)
+++ sd/trunk/Makefile.PL	Tue Aug 12 08:55:10 2008
@@ -6,9 +6,9 @@
 version_from('lib/App/SD.pm');
 
 requires 'Prophet'; # URI UNIVERSAL::require Params::Validate Path::Class Class::Accessor
+requires('Clone');
 requires('Moose'); # Moose::Role
-requires('HTTP::Date');
-
+requires('DateTime');
 features(
     'RT sync' => [
         -default => 0,

Modified: sd/trunk/bin/sd
==============================================================================
--- sd/trunk/bin/sd	(original)
+++ sd/trunk/bin/sd	Tue Aug 12 08:55:10 2008
@@ -6,19 +6,233 @@
 
 $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} || $ENV{'HOME'}.'/.sd';
 
-# Moose likes generating very noisy backtraces. Most users don't need to see
-# anything more than the root cause of the failure. Developers and the curious
-# can set environment variable SD_VERBOSE_ERROR to retain the backtraces.
-# When Moose's error throwing is more malleable we should switch to using that.
-unless ($ENV{SD_VERBOSE_ERROR} || $ENV{'TEST_VERBOSE'}) {
-    $SIG{__DIE__} = sub {
-        my $line = shift;
-        $line =~ s/\n.*//s if ($line =~ /at line/s);
-        $line .= "\n"; $line =~ s/\n+$/\n/gs;
-        die $line;
-    };
+use Prophet::CLI;
+use App::SD::Model::Ticket;
+
+package App::SD::CLI::Command;
+use Moose::Role;
+use Path::Class;
+
+sub get_content {
+    my $self = shift;
+    my $type = shift;
+
+    my $content;
+    if (my $file = file(delete $self->args->{'file'})) {
+        $content = $file->slurp();
+        $self->args->{'name'} = $file->basename;
+    } elsif ($content = delete $self->args->{'content'}) {
+
+    } elsif (exists $self->args->{'edit'}) {
+        $content = $self->edit_text('');
+    } else {
+        print "Please type your $type and press ctrl-d.\n";
+        $content = do { local $/; <> };
+    }
+
+    chomp $content;
+    return $content;
 }
 
-my $cli = Prophet::CLI->new({ app_class => 'App::SD' });
+package App::SD::CLI::Model::Ticket;
+use Moose::Role;
+use constant record_class => 'App::SD::Model::Ticket';
+
+package App::SD::CLI::Model::TicketComment;
+use Moose::Role;
+use constant record_class => 'App::SD::Model::Comment';
+
+package App::SD::CLI::Model::Attachment;
+use Moose::Role;
+use constant record_class => 'App::SD::Model::Attachment';
+
+
+
+
+
+package App::SD::CLI::Command::Ticket::Comment::Create;
+use Moose;
+
+extends 'Prophet::CLI::Command::Create';
+with 'App::SD::CLI::Model::TicketComment';
+with 'App::SD::CLI::Command';
+
+override run => sub  {
+    my $self = shift;
+    $self->args->{'ticket'} = $self->cli->uuid;
+    $self->args->{'content'} = $self->get_content('comment');
+    super(@_);
+};
+# override args to feed in that ticket's uuid as an argument to the comment
+
+
+
+package App::SD::CLI::Command::Attachment::Create;
+use Moose;
+extends 'Prophet::CLI::Command::Create';
+with 'App::SD::CLI::Model::Attachment';
+with 'App::SD::CLI::Command';
+
+override run => sub {
+    my $self = shift;
+    $self->args->{'content'} = $self->get_content('attachment');
+    super(@_);
+
+};
+
+package App::SD::CLI::Command::Ticket::Attachment::Create;
+use Moose;
+extends 'App::SD::CLI::Command::Attachment::Create';
+# override args to feed in that ticket's uuid as an argument to the comment
+
+override run => sub  {
+    my $self = shift;
+    $self->args->{'ticket'} = $self->cli->uuid;
+    super(@_);
+};
+
+
+package App::SD::CLI::Command::Ticket::Attachment::Search;
+use Moose;
+extends 'Prophet::CLI::Command::Search';
+with 'Prophet::CLI::RecordCommand';
+with 'App::SD::CLI::Model::Attachment';
+# override args to feed in that ticket's uuid as an argument to the comment
+
+
+sub type {'attachment'}
+sub get_search_callback {
+    my $self = shift;
+    return sub {
+        shift->prop('ticket') eq $self->uuid ? 1 : 0;
+        }
+
+}
+
+
+package App::SD::CLI::Command::Attachment::Content;
+use Moose;
+extends 'Prophet::CLI::Command::Show';
+with 'App::SD::CLI::Model::Attachment';
+with 'App::SD::CLI::Command';
+
+sub run {
+    my $self = shift;
+    my $record =  $self->_get_record_class;
+    $record->load(uuid => $self->cli->uuid);
+    print $record->prop('content');
+}
+
+package App::SD::CLI::Command::Help;
+use Moose; 
+with 'App::SD::CLI::Command';
+
+sub run {
+
+print <<EOF
+
+$0 ticket create --summary "This is a summary" --status new --somekey value
+$0 ticket update --uuid <uuid> --status resolved
+$0 ticket search --regex .
+$0 ticket delete --uuid <uuid>
+$0 ticket show --uuid <uuid>
+$0 pull --from remote-url
+
+$0 help  
+    Show this file
+
+EOF
+
+}
+
+package App::SD::CLI::Command::Ticket::Show;
+use Moose;
+extends 'Prophet::CLI::Command::Show';
+with 'App::SD::CLI::Command';
+with 'App::SD::CLI::Model::Ticket';
+
+package App::SD::CLI::Command::Details;
+use Moose;
+with 'App::SD::CLI::Command';
+with 'App::SD::CLI::Model::Ticket';
+
+sub run {
+    my $self = shift;
+    print "\n=head1 METADATA\n\n"; 
+    $self->App::SD::CLI::Command::Ticket::Show::run();
+    print "\n=head1 ATTACHMENTS\n\n";
+    use Clone;
+    my $foo = Clone::clone($self);
+    $foo->type('attachment');
+    bless $foo, 'App::SD::CLI::Command::Ticket::Attachment::Search';
+    $foo->run;
+    print "\n=head1 COMMENTS\n\n";
+    my $bar = Clone::clone($self);
+    bless $bar, 'App::SD::CLI::Command::Ticket::Comments';
+    $bar->type('comment');
+    $bar->App::SD::CLI::Command::Ticket::Comments::run();
+}
+
+package App::SD::CLI::Command::Ticket::Comments;
+use Moose;
+extends 'Prophet::CLI::Command';
+with 'Prophet::CLI::RecordCommand';
+with 'App::SD::CLI::Model::Ticket';
+
+sub run {
+    my $self = shift;
+    my $record = $self->_get_record_class();
+    $record->load( uuid => $self->uuid );
+    unless (@{$record->comments}) {
+        print "No comments found\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";
+    }
+
+}
+
+
+package App::SD::CLI::Command::Merge;
+use Moose;
+extends qw/Prophet::CLI::Command::Merge/;
+with 'App::SD::CLI::Command';
+
+package App::SD::CLI::Command::Push;
+use Moose;
+extends qw/App::SD::CLI::Command::Merge/;
+
+sub run {
+    my $self = shift; 
+    local $ENV{PROPHET_RESOLVER} = 'Prompt';
+    bless $self, 'App::SD::CLI::Command::Merge';
+    $self->args( {to => $self->args->{'to'}, from => $self->app_handle->default_replica_type.":file://".$self->app_handle->handle->fs_root });
+    $self->run; 
+}
+
+package App::SD::CLI::Command::Pull;
+use Moose; 
+extends qw/App::SD::CLI::Command::Merge/;
+
+sub run {
+    my $self = shift; 
+
+    die "Please specify a --from.\n" if !defined($self->args->{'from'});
+
+    local $ENV{PROPHET_RESOLVER} = 'Prompt';
+    bless $self, 'App::SD::CLI::Command::Merge';
+    $self->args({  from => $self->args->{'from'}, 
+                   to => $self->cli->app_handle->default_replica_type.":file://".$self->cli->app_handle->handle->fs_root });
+    $self->run; 
+}
+
+package main;
+
+my $cli = Prophet::CLI->new( { app_class => 'App::SD' } );
 $cli->run_one_command;
 
+
+1;

Modified: sd/trunk/lib/App/SD/Model/Attachment.pm
==============================================================================
--- sd/trunk/lib/App/SD/Model/Attachment.pm	(original)
+++ sd/trunk/lib/App/SD/Model/Attachment.pm	Tue Aug 12 08:55:10 2008
@@ -9,6 +9,8 @@
 use constant collection_class => 'App::SD::Collection::Attachment';
 use constant type => 'attachment';
 
+use constant summary_format => '%l %s %s';
+use constant summary_props => qw(name content_type);
 
 sub _default_summary_format { '%s,$luid | %s,name | %s,content_type'}
 

Modified: sd/trunk/lib/App/SD/Model/Ticket.pm
==============================================================================
--- sd/trunk/lib/App/SD/Model/Ticket.pm	(original)
+++ sd/trunk/lib/App/SD/Model/Ticket.pm	Tue Aug 12 08:55:10 2008
@@ -1,7 +1,6 @@
 package App::SD::Model::Ticket;
 use Moose;
 extends 'App::SD::Record';
-
 use Term::ANSIColor;
 use HTTP::Date;
 

Modified: sd/trunk/lib/App/SD/Replica/Hiveminder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/Hiveminder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/Hiveminder.pm	Tue Aug 12 08:55:10 2008
@@ -15,6 +15,17 @@
 
 use constant scheme => 'hm';
 
+# XXX: this should be called from superclass, or better, have individual attributes have their own builders.
+
+around 'new' => sub {
+    my ($next, $self, @args) = @_;
+    warn "around $self $next";
+    my $ret = $self->$next(@args);
+    $ret->setup;
+    warn "==> $ret";
+    return $ret;
+};
+
 
 =head2 setup
 
@@ -22,14 +33,13 @@
 
 =cut
 
-# XXX: this should be called from superclass, or better, have individual attributes have their own builders.
 
 sub BUILD {
     my $self = shift;
 
     require Net::Jifty;
     my ($server) = $self->{url} =~ m/^hm:(.*?)$/
-        or die "Can't parse Hiveminder server spec. Expected hm:http://hiveminder.com";
+        or die "Can't parse hiveminder server spec";
     $self->url($server);
     my $uri = URI->new($server);
     my ( $username, $password );

Modified: sd/trunk/lib/App/SD/Replica/Hiveminder/PullEncoder.pm
==============================================================================

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	Tue Aug 12 08:55:10 2008
@@ -27,6 +27,16 @@
 };
 
 
+# XXX: this should be called from superclass, or better, have individual attributes have their own builders.
+
+around 'new' => sub {
+    my ($next, $self, @args) = @_;
+    my $ret = $self->$next(@args);
+    $ret->setup;
+    return $ret;
+};
+
+
 use File::Temp 'tempdir';
 
 sub setup {
@@ -38,7 +48,7 @@
     require RT::Client::REST::Ticket;
 
     my ( $server, $type, $query ) = $self->{url} =~ m/^rt:(.*?)\|(.*?)\|(.*)$/
-        or die "Can't parse RT server spec. Expected rt:http://example.com|QUEUE|QUERY. Try: rt:http://example.com/|General|";
+        or die "Can't parse rt server spec";
     my $uri = URI->new($server);
     my ( $username, $password );
     if ( my $auth = $uri->userinfo ) {

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	Tue Aug 12 08:55:10 2008
@@ -73,7 +73,11 @@
     return $ticket;
 }
 
-=head2 find_matching_tickets QUERY
+    my @changesets;
+    for my $txn ( sort { $b->{'id'} <=> $a->{'id'} } @{ $args{'transactions'} } ) {
+            my $changeset = $self->txn_to_changeset($txn, $ticket, $create_state);
+            unshift @changesets, $changeset if $changeset->has_changes;
+        }
 
 Returns an RT::Client ticket collection for all tickets found matching your QUERY string.
 

Modified: sd/trunk/t/attachment-content.t
==============================================================================

Modified: sd/trunk/t/sd-attachments.t
==============================================================================
--- sd/trunk/t/sd-attachments.t	(original)
+++ sd/trunk/t/sd-attachments.t	Tue Aug 12 08:55:10 2008
@@ -21,7 +21,7 @@
 
 my $attachment_id;
 my $attachment_uuid;
-run_output_matches('sd', [qw/ticket attachment create --uuid/, $yatta_uuid, '--content', 'stub', '--', '--name', "paper_order.doc"], [qr/Created attachment (\d+)(?{ $attachment_id = $1}) \((.*)(?{ $attachment_uuid = $2})\)/], [], "Added a attachment");
+run_output_matches('sd', [qw/ticket attachment create --uuid/, $yatta_uuid, '--content', 'stub', '--name', "paper_order.doc"], [qr/Created attachment (\d+)(?{ $attachment_id = $1}) \((.*)(?{ $attachment_uuid = $2})\)/], [], "Added a attachment");
 ok($attachment_id, " $attachment_id = $attachment_uuid");
 
 run_output_matches('sd', [qw/ticket attachment list --uuid/, $yatta_uuid], [qr/\d+ paper_order.doc text\/plain/,], [], "Found the attachment");
@@ -43,7 +43,6 @@
 run_output_matches(
     'sd',
     [   qw/ticket attachment update --uuid/, $attachment_uuid,
-        '--',
         qw/--name/,                          "plague_recipe.doc"
     ],
     [qr/attachment \d+ \($attachment_uuid\) updated/],
@@ -52,7 +51,7 @@
 );
 run_output_matches(
     'sd',
-    [ qw/ticket attachment show --batch --uuid/, $attachment_uuid ],
+    [ qw/ticket attachment show --uuid/, $attachment_uuid ],
     [  
         qr/id: (\d+) \($attachment_uuid\)/, 
         "content: stub",

Modified: sd/trunk/t/sd-rt.t
==============================================================================



More information about the Bps-public-commit mailing list