about summary refs log tree commit diff
path: root/lib/jitterbug
diff options
context:
space:
mode:
Diffstat (limited to 'lib/jitterbug')
-rw-r--r--lib/jitterbug/Emailer.pm26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/jitterbug/Emailer.pm b/lib/jitterbug/Emailer.pm
index 648c72f..4bf2e51 100644
--- a/lib/jitterbug/Emailer.pm
+++ b/lib/jitterbug/Emailer.pm
@@ -3,6 +3,7 @@ package jitterbug::Emailer;
 use strict;
 use warnings;
 use Email::Stuff;
+use JSON;
 
 sub new {
     my $self = bless {} => shift;
@@ -16,30 +17,33 @@ sub new {
 }
 
 sub run {
-    my $self = shift;
-    my $task = $self->{'task'};
-    my $buildconf = $self->{'conf'}->{'jitterbug'}{'build_process'};
-    my $project   = $task->project->name;
+    my $self       = shift;
+    my $task       = $self->{'task'};
+    my $buildconf  = $self->{'conf'}->{'jitterbug'}{'build_process'};
+    my $project    = $task->project->name;
     my $tap_output = $self->{'tap_output'};
-    my $sha1 = $task->commit->sha256;
-    my $desc = JSON::decode_json( $task->commit->content );
-    my $email = $desc->{'author'}{'email'};
+    my $sha1       = $task->commit->sha256;
+    my $desc       = JSON::decode_json( $task->commit->content );
+    my $email      = $desc->{'author'}{'email'};
 
     my $body = <<BODY;
 $tap_output
 BODY
 
-    Email::Stuff->from($buildconf->{'on_failure_from_email'})
-                ->to($email)
+    my $stuff = Email::Stuff->from($buildconf->{'on_failure_from_email'})
+                # bug in Email::Stuff brakes chaining if $email is empty
+                ->to($email || " ")
                 ->cc($buildconf->{'on_failure_cc_email'})
                 ->text_body($body)
                 ->subject(
                     $buildconf->{'on_failure_subject_prefix'} . "$project @ $sha1"
-                  )
+                  );
                 # Should we attach a build log for convenience?
                 # ->attach(io('dead_bunbun_faked.gif')->all,
                 #    filename => 'dead_bunbun_proof.gif')
-                ->send;
+    $self->{'last_email_sent'} = $stuff;
+
+    $stuff->send;
 
     return $self;
 }