Skip to content

Commit

Permalink
Implement dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
robertkrimen committed Apr 6, 2009
1 parent ab8517b commit 601896f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,10 +1,11 @@
TODO:
- Image fetching/uploading
- Implement dry-run
- Config checker
- Generate better config stub
- Improve history display

Sunday April 05 14:56:51 PDT 2009:
- Implement dry-run
- Improve logging
- Add reporting
- Datetime as "* ago"
Expand Down
71 changes: 50 additions & 21 deletions lib/App/PM/Announce.pm
Expand Up @@ -41,6 +41,21 @@ sub BUILD {
$self->startup;
}

has debug => qw/is ro lazy_build 1/;
sub _build_debug {
return $ENV{APP_PM_ANNOUNCE_DEBUG} ? 1 : 0;
}

has verbose => qw/is ro lazy_build 1/;
sub _build_verbose {
return 0;
}

has dry_run => qw/is ro lazy_build 1/;
sub _build_dry_run {
return 0;
}

has home_dir => qw/is ro lazy_build 1/;
sub _build_home_dir {
my @home_dir;
Expand Down Expand Up @@ -83,11 +98,6 @@ sub _build_log_file {
return shift->home_dir->file( 'log' );
}

has debug => qw/is ro lazy_build 1/;
sub _build_debug {
return $ENV{APP_PM_ANNOUNCE_DEBUG} ? 1 : 0;
}

has logger => qw/is ro isa Log::Dispatch lazy_build 1/;
sub _build_logger {
my $self = shift;
Expand Down Expand Up @@ -158,6 +168,10 @@ sub _build_history {
sub startup {
my $self = shift;

$self->logger->debug( "debug = " . $self->debug );
$self->logger->debug( "verbose = " . $self->verbose );
$self->logger->debug( "dry-run = " . $self->dry_run );

my $home_dir = $self->home_dir;
$self->logger->debug( "home_dir = $home_dir" );

Expand Down Expand Up @@ -220,18 +234,23 @@ sub announce {
push @report, "Already announced on meetup";
}
elsif ($self->feed->{meetup}) {
die "Didn't announce on meetup" unless $result = $self->feed->{meetup}->announce( %event );
my $meetup_link = $event->{meetup_link} = $result->{meetup_link};
$self->logger->debug( "Meetup link is " . $meetup_link );
$self->logger->info( "\"$event{title}\" ($uuid) announced to meetup ($meetup_link) " );
$self->history->update( $uuid => did_meetup => 1, meetup_link => "$meetup_link" );
push @report, "Announced on meetup";
unless ($self->dry_run) {
die "Didn't announce on meetup" unless $result = $self->feed->{meetup}->announce( %event );
my $meetup_link = $event->{meetup_link} = $result->{meetup_link};
$self->logger->debug( "Meetup link is " . $meetup_link );
$self->logger->info( "\"$event{title}\" ($uuid) announced to meetup ($meetup_link) " );
$self->history->update( $uuid => did_meetup => 1, meetup_link => "$meetup_link" );
push @report, "Announced on meetup";
}
else {
push @report, "Would announce on meetup";
}
}
else {
$self->logger->debug( "No feed configured for meetup" );
}

die "Don't have a Meetup link" unless $event->{meetup_link};
die "Don't have a Meetup link" unless $self->dry_run || $event->{meetup_link};

$event{description} = [ $event{description}, $event->{meetup_link} ];

Expand All @@ -240,10 +259,15 @@ sub announce {
push @report, "Already announced on linkedin";
}
elsif ($self->feed->{linkedin}) {
die "Didn't announce on linkedin" unless $result = $self->feed->{linkedin}->announce( %event );
$self->logger->info( "\"$event{title}\" ($uuid) announced to linkedin" );
$result = $self->history->update( $uuid => did_linkedin => 1 );
push @report, "Announced on linkedin";
unless ($self->dry_run) {
die "Didn't announce on linkedin" unless $result = $self->feed->{linkedin}->announce( %event );
$self->logger->info( "\"$event{title}\" ($uuid) announced to linkedin" );
$result = $self->history->update( $uuid => did_linkedin => 1 );
push @report, "Announced on linkedin";
}
else {
push @report, "Would announce on linkedin";
}
}
else {
$self->logger->debug( "No feed configured for linkedin" );
Expand All @@ -254,17 +278,22 @@ sub announce {
push @report, "Already announced on greymatter";
}
elsif ($self->feed->{greymatter}) {
die "Didn't announce on greymatter" unless $result = $self->feed->{greymatter}->announce( %event );
$self->logger->info( "\"$event{title}\" ($uuid) announced to greymatter" );
$result = $self->history->update( $uuid => did_greymatter => 1 );
push @report, "Announced on greymatter";
unless ($self->dry_run) {
die "Didn't announce on greymatter" unless $result = $self->feed->{greymatter}->announce( %event );
$self->logger->info( "\"$event{title}\" ($uuid) announced to greymatter" );
$result = $self->history->update( $uuid => did_greymatter => 1 );
push @report, "Announced on greymatter";
}
else {
push @report, "Would announce on greymatter";
}
}
else {
$self->logger->debug( "No feed configured for greymatter" );
}
};
if ($@) {
warn "Unable to announce \"$event->{title}\" ($uuid)\n";
warn "Unable to announce \"$event{title}\" ($uuid)\n";
die $@;
}

Expand Down
7 changes: 4 additions & 3 deletions lib/App/PM/Announce/App.pm
Expand Up @@ -17,10 +17,11 @@ sub app {

sub run {
Getopt::Chain->process(
options => [qw/ verbose|v /],
options => [qw/ verbose|v dry-run|n /],
run => sub {
my ($context, @arguments) = @_;
push @app, qw/debug 1/ if $context->option( 'verbose' );
push @app, qw/debug 1 verbose 1/ if $context->option( 'verbose' );
push @app, qw/dry_run 1/ if $context->option( 'dry-run' );
return if @arguments;
app;
print <<_END_;
Expand Down Expand Up @@ -79,7 +80,7 @@ _END_
my ($event, $report) = app->announce( \*STDIN );
if ($event) {
print "\n";
print join "\n", @$report, '', '';
print join "\n", @$report, '', '' if @$report;
print "\"$event->{title}\" has been announced on ", join( ', ', map { $event->{"did_$_"} ? $_ : () } qw/meetup linkedin greymatter/ ), "\n";
print "The Meetup link is $event->{meetup_link}", "\n" if $event->{meetup_link};
print "\n";
Expand Down

0 comments on commit 601896f

Please sign in to comment.