[Bps-public-commit] r16577 - in sd/branches/sd-dispatcher: . lib/App lib/App/SD/CLI/Command lib/App/SD/CLI/Command/Help lib/App/SD/CLI/Model lib/App/SD/Model lib/App/SD/Replica lib/App/SD/Replica/hm t
sartak at bestpractical.com
sartak at bestpractical.com
Tue Oct 28 14:20:48 EDT 2008
Author: sartak
Date: Tue Oct 28 14:20:48 2008
New Revision: 16577
Added:
sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help/Config.pm
sd/branches/sd-dispatcher/lib/App/SD/Config.pm
sd/branches/sd-dispatcher/t/05-config-file-loading.t
sd/branches/sd-dispatcher/t/prophet_testing.conf
Modified:
sd/branches/sd-dispatcher/ (props changed)
sd/branches/sd-dispatcher/lib/App/SD.pm
sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help.pm
sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help/Environment.pm
sd/branches/sd-dispatcher/lib/App/SD/CLI/Model/Ticket.pm
sd/branches/sd-dispatcher/lib/App/SD/Model/Ticket.pm
sd/branches/sd-dispatcher/lib/App/SD/Replica/hm.pm
sd/branches/sd-dispatcher/lib/App/SD/Replica/hm/PushEncoder.pm
sd/branches/sd-dispatcher/lib/App/SD/Test.pm
sd/branches/sd-dispatcher/t/sd-comments.t
Log:
Bring sd-dispatcher up to trunk
Modified: sd/branches/sd-dispatcher/lib/App/SD.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD.pm (original)
+++ sd/branches/sd-dispatcher/lib/App/SD.pm Tue Oct 28 14:20:48 2008
@@ -1,9 +1,16 @@
package App::SD;
use Moose;
+use App::SD::Config;
extends 'Prophet::App';
our $VERSION = '0.01';
+has +config => (
+ default => sub {
+ my $self = shift;
+ return App::SD::Config->new(app_handle => $self);
+ }
+);
sub database_settings {
{
Modified: sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help.pm (original)
+++ sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help.pm Tue Oct 28 14:20:48 2008
@@ -43,6 +43,7 @@
$cmd help attachments - Working with ticket attachments
$cmd help sync - Publishing and importing ticket databases
$cmd help environment - Environment variables which affect sd
+$cmd help config - Database configuration variables
EOF
Added: sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help/Config.pm
==============================================================================
--- (empty file)
+++ sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help/Config.pm Tue Oct 28 14:20:48 2008
@@ -0,0 +1,30 @@
+package App::SD::CLI::Command::Help::Config;
+use Moose;
+extends 'App::SD::CLI::Command::Help';
+
+sub run {
+ my $self = shift;
+ $self->print_header('Configuration Options');
+
+print <<EOF
+ SD supports both a user-wide configuration (\$HOME/.sdrc and per-database
+ configuration (/path/to/repo/sdrc). If both configuration files are present,
+ the database-specific config file will be used.
+
+ Currently, the following configuration variables are available:
+
+ reporter_email = foo\@bar.com
+ Specifies an email address to use as the default for tickets'
+ reported_by field.
+
+ summary_format_ticket = %4s },\$luid | %-11.11s,status | %-60.60s,summary
+ Specifies how to format ticket summaries (when listing tickets, e.g.).
+EOF
+
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
+
Modified: sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help/Environment.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help/Environment.pm (original)
+++ sd/branches/sd-dispatcher/lib/App/SD/CLI/Command/Help/Environment.pm Tue Oct 28 14:20:48 2008
@@ -9,6 +9,9 @@
print <<EOF
export SD_REPO=/path/to/sd/replica
Specify where the ticket database SD is using should reside
+
+ export SD_CONFIG=/path/to/sd/config/file
+ Specify where the configuration file SD is using should reside
EOF
}
Modified: sd/branches/sd-dispatcher/lib/App/SD/CLI/Model/Ticket.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD/CLI/Model/Ticket.pm (original)
+++ sd/branches/sd-dispatcher/lib/App/SD/CLI/Model/Ticket.pm Tue Oct 28 14:20:48 2008
@@ -160,7 +160,7 @@
# glue all the parts together
return join(
- "\n\n",
+ "\n",
$self->_build_template_section(
header => metadata_separator,
Added: sd/branches/sd-dispatcher/lib/App/SD/Config.pm
==============================================================================
--- (empty file)
+++ sd/branches/sd-dispatcher/lib/App/SD/Config.pm Tue Oct 28 14:20:48 2008
@@ -0,0 +1,34 @@
+package App::SD::Config;
+use Moose;
+use File::Spec;
+
+extends 'Prophet::Config';
+
+# We can't just frob $ENV{PROPHET_APP_CONFIG} the way the sd script does
+# with $ENV{PROPHET_REPO} because we need to instantiate App::SD::CLI to
+# get the location of the repo root, and then Prophet would load its own
+# config file before we got around to messing with the env var
+before 'app_config_file' => sub {
+ my $self = shift;
+
+ # The order of preference for config files is:
+ # $ENV{SD_CONFIG} > fs_root/sdrc > fs_root/prophetrc (for backcompat)
+ # $HOME/.sdrc > $ENV{PROPHET_APP_CONFIG} > $HOME/.prophetrc
+
+ $ENV{'PROPHET_APP_CONFIG'}
+ = $self->file_if_exists($ENV{'SD_CONFIG'})
+ || $self->file_if_exists(
+ File::Spec->catfile($self->app_handle->handle->fs_root => 'sdrc'))
+ || $self->file_if_exists(
+ # backcompat
+ File::Spec->catfile($self->app_handle->handle->fs_root => 'prophetrc'))
+ || $self->file_if_exists(
+ File::Spec->catfile($ENV{'HOME'}.'/.sdrc'))
+ || $ENV{'PROPHET_APP_CONFIG'} # don't overwrite with nothing
+ || ''; # don't write undef
+};
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
Modified: sd/branches/sd-dispatcher/lib/App/SD/Model/Ticket.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD/Model/Ticket.pm (original)
+++ sd/branches/sd-dispatcher/lib/App/SD/Model/Ticket.pm Tue Oct 28 14:20:48 2008
@@ -34,7 +34,7 @@
=cut
sub default_prop_reported_by {
- shift->app_handle->config->{reporter_email} or $ENV{EMAIL}
+ shift->app_handle->config->get('reporter_email') or $ENV{EMAIL}
}
=head2 canonicalize_prop_status
Modified: sd/branches/sd-dispatcher/lib/App/SD/Replica/hm.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD/Replica/hm.pm (original)
+++ sd/branches/sd-dispatcher/lib/App/SD/Replica/hm.pm Tue Oct 28 14:20:48 2008
@@ -162,6 +162,7 @@
completed_at => 'completed',
due => 'due',
creator => 'creator',
+ milestone => '_delete',
attachment_count => '_delete',
depended_on_by_count => '_delete',
depended_on_by_summaries => '_delete',
Modified: sd/branches/sd-dispatcher/lib/App/SD/Replica/hm/PushEncoder.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD/Replica/hm/PushEncoder.pm (original)
+++ sd/branches/sd-dispatcher/lib/App/SD/Replica/hm/PushEncoder.pm Tue Oct 28 14:20:48 2008
@@ -163,7 +163,8 @@
my $self = shift;
my ($change) = validate_pos( @_, { isa => 'Prophet::Change' } );
- my %props = map { $_->name => $_->new_value } $change->prop_changes;
+ my %props = $self->translate_props( $change );
+ #my %props = map { $_->name => $_->new_value } $change->prop_changes;
my %attr;
for my $key ( keys %props ) {
Modified: sd/branches/sd-dispatcher/lib/App/SD/Test.pm
==============================================================================
--- sd/branches/sd-dispatcher/lib/App/SD/Test.pm (original)
+++ sd/branches/sd-dispatcher/lib/App/SD/Test.pm Tue Oct 28 14:20:48 2008
@@ -9,8 +9,8 @@
use Cwd qw/getcwd/;
use base qw/Exporter/;
our @EXPORT = qw(create_ticket_ok create_ticket_with_editor_ok create_ticket_comment_ok get_uuid_for_luid get_luid_for_uuid);
-$ENV{'EMAIL'} = "someone\@example.com";
-$ENV{'PROPHET_APP_CONFIG'} = "t/prophet_testing.conf";
+$ENV{'SD_CONFIG'} = 't/prophet_testing.conf';
+delete $ENV{'PROPHET_APP_CONFIG'};
=head2 create_ticket_ok ARGS
@@ -168,3 +168,20 @@
$ENV{'EDITOR'} = File::Spec->catfile(getcwd(), 't', 'scripts', $script);
diag 'export EDITOR=' . $ENV{'EDITOR'} . "\n";
}
+
+=head2 write_to_file FILENAME DATA
+
+Takes the string given in DATA and writes it to the file whose name is given
+by FILENAME.
+
+=cut
+
+sub write_to_file {
+ my ($self, $filename, $data) = @_;
+
+ open FH, '>', $filename;
+ print FH $data;
+ close FH;
+}
+
+1;
Added: sd/branches/sd-dispatcher/t/05-config-file-loading.t
==============================================================================
--- (empty file)
+++ sd/branches/sd-dispatcher/t/05-config-file-loading.t Tue Oct 28 14:20:48 2008
@@ -0,0 +1,110 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Prophet::Test tests => 10;
+use App::SD::Test;
+use File::Temp qw/tempdir/;
+use Path::Class;
+
+
+no warnings 'once';
+
+BEGIN {
+ require File::Temp;
+ $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} = $ENV{'HOME'} = File::Temp::tempdir( CLEANUP => 0 ) . '/_svb';
+ diag "export SD_REPO=".$ENV{'PROPHET_REPO'} ."\n";
+ diag "export HOME=".$ENV{'PROPHET_REPO'} ."\n";
+ $ENV{'PROPHET_APP_CONFIG'} = undef; # clear this because Prophet::Test sets it
+}
+
+# Tests the config file order of preference laid out in App::SD::Config
+
+# create from sd
+my ($yatta_id, $yatta_uuid) = create_ticket_ok( '--summary', 'YATTA');
+
+# default config file
+diag("Testing default config file\n");
+
+run_output_matches( 'sd', [ 'ticket',
+ 'list', '--regex', '.' ],
+ [ qr/(\d+) YATTA new/]
+);
+
+$ENV{'SD_CONFIG'} = $ENV{'PROPHET_APP_CONFIG'} = undef; # override App::SD::Test
+ok( ! $ENV{'SD_CONFIG'}, "SD_CONFIG env var has been cleared" );
+ok( ! $ENV{'PROPHET_APP_CONFIG'}, "PROPHET_APP_CONFIG env var has been cleared" );
+
+# Test from least-preferred to most preferred, leaving the least-preferred
+# files in place to make sure the next-most-preferred file is preferred
+# over all the files beneath it.
+
+diag("Testing \$HOME/.prophetrc\n");
+
+my $config_filename = $ENV{'HOME'} . '/.prophetrc';
+
+App::SD::Test->write_to_file($config_filename,
+ "summary_format_ticket = %4s },\$luid | %-11.11s,status | %-60.60s,summary\n");
+
+run_output_matches( 'sd', [ 'ticket',
+ 'list', '--regex', '.' ],
+ [ qr/\s+(\d+) } new YATTA/]
+);
+
+diag("Testing PROPHET_APP_CONFIG\n");
+
+$config_filename = $ENV{'HOME'} . '/config-test';
+$ENV{'PROPHET_APP_CONFIG'} = $config_filename;
+
+App::SD::Test->write_to_file($config_filename,
+ "summary_format_ticket = %-9.9s,status | %-60.60s,summary\n");
+
+run_output_matches( 'sd', [ 'ticket',
+ 'list', '--regex', '.' ],
+ [ qr/new YATTA/]
+);
+
+diag("Testing \$HOME/.sdrc\n");
+
+$config_filename = $ENV{'HOME'} . '/.sdrc';
+
+App::SD::Test->write_to_file($config_filename,
+ "summary_format_ticket = %4s },\$luid | %-7.7s,status | %-60.60s,summary\n");
+
+run_output_matches( 'sd', [ 'ticket',
+ 'list', '--regex', '.' ],
+ [ qr/\s+(\d+) } new YATTA/]
+);
+
+diag("Testing fs_root/prophetrc\n");
+
+$config_filename = $ENV{'SD_REPO'} . '/prophetrc';
+
+App::SD::Test->write_to_file($config_filename,
+ "summary_format_ticket = %4s },\$luid | %-10.10s,status | %-60.60s,summary\n");
+
+run_output_matches( 'sd', [ 'ticket',
+ 'list', '--regex', '.' ],
+ [ qr/\s+(\d+) } new YATTA/]
+);
+
+diag("Testing fs_root/sdrc\n");
+
+$config_filename = $ENV{'SD_REPO'} . '/sdrc';
+
+App::SD::Test->write_to_file($config_filename,
+ "summary_format_ticket = %4s },\$luid | %-6.6s,status | %-60.60s,summary\n");
+
+run_output_matches( 'sd', [ 'ticket',
+ 'list', '--regex', '.' ],
+ [ qr/\s+(\d+) } new YATTA/]
+);
+
+diag("Testing SD_CONFIG\n");
+
+$ENV{'SD_CONFIG'} = 't/prophet_testing.conf';
+
+run_output_matches( 'sd', [ 'ticket',
+ 'list', '--regex', '.' ],
+ [ qr/(\d+) YATTA new/]
+);
Added: sd/branches/sd-dispatcher/t/prophet_testing.conf
==============================================================================
--- (empty file)
+++ sd/branches/sd-dispatcher/t/prophet_testing.conf Tue Oct 28 14:20:48 2008
@@ -0,0 +1 @@
+reporter_email = someone at example.com
Modified: sd/branches/sd-dispatcher/t/sd-comments.t
==============================================================================
--- sd/branches/sd-dispatcher/t/sd-comments.t (original)
+++ sd/branches/sd-dispatcher/t/sd-comments.t Tue Oct 28 14:20:48 2008
@@ -2,7 +2,7 @@
use strict;
-use Prophet::Test tests => 8;
+use Prophet::Test tests => 10;
use App::SD::Test;
no warnings 'once';
@@ -45,6 +45,7 @@
[],
"Found the comment"
);
+
run_output_matches(
'sd',
[ qw/ticket comment update --uuid/, $comment_uuid,
@@ -55,6 +56,7 @@
[],
"updated the comment"
);
+
run_output_matches(
'sd',
[ qw/ticket comment show --batch --uuid/, $comment_uuid ],
@@ -76,3 +78,30 @@
[],
"Found the comment when we tried to search for all comments on a ticket by the ticket's uuid"
);
+
+run_output_matches(
+ 'sd',
+ [ qw/ticket comment update --uuid/, $comment_uuid,
+ '--',
+ qw/--content/, "A\nmultiline\ncomment"
+ ],
+ [qr/comment \d+ \($comment_uuid\) updated/],
+ [],
+ "updated the comment to a multiline content"
+);
+
+run_output_matches(
+ 'sd',
+ [ qw/ticket comment show --batch --uuid/, $comment_uuid ],
+ [ qr/id: (\d+) \($comment_uuid\)/,
+ qr/^content: A/,
+ qr/^multiline$/,
+ qr/^comment$/,
+ qr/created: /i,
+ qr/creator: /i,
+ "original_replica: $replica_uuid",
+ "ticket: $yatta_uuid"
+ ],
+ [],
+ "Found the comment new version"
+);
More information about the Bps-public-commit
mailing list