| 1 | package Giovanni::Plugins::Hipchat; | ||
| 2 | |||
| 3 | use Mouse::Role; | ||
| 4 | use Data::Dumper; | ||
| 5 | use LWP::UserAgent; | ||
| 6 | use LWP::Protocol::https; | ||
| 7 | |||
| 8 | around 'send_notify' => sub { | ||
| 9 | my ( $orig, $self, $ssh ) = @_; | ||
| 10 | |||
| 11 | print "notify via HipChat\n"; | ||
| 12 | my @tos = split(/\s*,\s*/, $self->config->{hipchat_rooms}); | ||
| 13 | my $msg = $ENV{USER} | ||
| 14 | . ' just ran a ' | ||
| 15 | . $self->config->{command} . ' for ' | ||
| 16 | . $self->config->{project} . ' on ' | ||
| 17 | . $ssh->get_host; | ||
| 18 | my $ua = LWP::UserAgent->new(); | ||
| 19 | my $url = 'https://api.hipchat.com/v1/rooms/message?format=json&auth_token='.$self->config->{hipchat_token}; | ||
| 20 | foreach my $to (@tos){ | ||
| 21 | $ua->post($url, { | ||
| 22 | room_id => $to, | ||
| 23 | from => 'Giovanni', | ||
| 24 | message => $msg, | ||
| 25 | message_format => 'text', | ||
| 26 | notify => 1, | ||
| 27 | color => 'green', | ||
| 28 | }); | ||
| 29 | } | ||
| 30 | }; | ||
| 31 | |||
| 32 | 1; | ||
| 33 | |||
| 34 | __END__ |