Created
March 28, 2013 08:30
-
-
Save mattn/5261612 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use 5.010000; | |
use autodie; | |
use Furl; | |
use JSON; | |
use GDBM_File; | |
use Encode; | |
use Growl::GNTP; | |
my $repo = shift || "mruby/mruby"; | |
my $dup_path = '/tmp/dup-travis-notify.db'; | |
my %dup; | |
unless ($ENV{DEBUG}) { | |
tie %dup, 'GDBM_File', $dup_path, &GDBM_WRCREAT, 0640; | |
} | |
my $ua = Furl->new(agent => $0, timeout => 10); | |
$ua->env_proxy; | |
my $growl = Growl::GNTP->new(AppName => "travis notify"); | |
$growl->register([ | |
{ Name => "succeeded" }, | |
{ Name => "failed" }, | |
]); | |
while (1) { | |
my $res = $ua->get("https://api.travis-ci.org/repositories/$repo/builds.json"); | |
if ($res->is_success) { | |
my $builds = decode_json($res->content); | |
for my $build (@{$builds}) { | |
next if $build->{state} ne 'finished'; | |
next if $build->{result} eq 0; | |
next if $dup{$build->{id}}++; | |
$growl->notify( | |
Name => "failed", | |
Title => $repo, | |
Message => "Build $build->{id} failed", | |
CallbackTarget => sprintf("https://travis-ci.org/$repo/builds/$build->{id}"), | |
); | |
} | |
} | |
sleep 30; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment