01 #!/usr/local/bin/perl -w 02 use strict; 03 use JSON qw( from_json ); 04 use DateTime; 05 use DateTime::Format::Strptime; 06 use Log::Log4perl qw(:easy); 07 use LWP::Simple qw( get ); 08 09 Log::Log4perl->easy_init($DEBUG); 10 11 my $github_api_url = 12 "https://api.github.com/repos"; 13 my $travis_api_url = 14 "http://travis-ci.org"; 15 16 my( $repo ) = @ARGV; 17 die "usage: $0 name/repo" if 18 !defined $repo; 19 20 my $build_json = get( 21 "$travis_api_url/$repo/builds.json" ); 22 my $build_data = from_json( $build_json ); 23 24 my $f = DateTime::Format::Strptime->new( 25 pattern => "%Y-%m-%dT%H:%M:%SZ", 26 time_zone => "America/Los_Angeles", 27 ); 28 29 my $last_week_dt = DateTime->today( 30 time_zone => "local" )-> 31 add( weeks => -1 ); 32 33 my %build_breakers = (); 34 35 for my $build ( @$build_data ) { 36 37 if( $build->{ result } == 0 ) { 38 DEBUG "Build $build->{ commit } ok"; 39 next; 40 } 41 42 my $build_dt = $f->parse_datetime( 43 $build->{ started_at } ); 44 45 if( $build_dt < $last_week_dt ) { 46 DEBUG "Ignoring old build $build_dt"; 47 } 48 49 my $github_request = 50 "$github_api_url/$repo/commits/" . 51 "$build->{ commit }"; 52 53 DEBUG "Fetching $github_request"; 54 55 my $github_json = get( 56 "$github_api_url/$repo/commits" . 57 "/$build->{ commit }" ); 58 my $github_data = 59 from_json( $github_json ); 60 61 my $committer = $github_data-> 62 { commit }->{ committer }->{ email }; 63 64 DEBUG "$committer broke build ", 65 "$build->{ commit }"; 66 $build_breakers{ $committer }++; 67 } 68 69 for my $build_breaker ( 70 sort keys %build_breakers ) { 71 print "$build_breaker: ", 72 "-$build_breakers{ $build_breaker }\n"; 73 }