Slight POD correction
[dbsrgits/DBIx-Class.git] / maint / travis_buildlog_downloader
CommitLineData
55586a63 1#!/usr/bin/env perl
2
3use warnings;
4use strict;
5
6# H::T does not support gzip/deflate out of the box, but you know what?
7# THAT'S OK BECAUSE TRAVIS' LOGSERVER DOESN'T EITHER </headdesk>
8use HTTP::Tiny;
9
10use JSON::PP;
11
12( my $build_id = $ARGV[0]||'' ) =~ /^[0-9]+$/
13 or die "Expecting a numeric build id as argument\n";
14
15my $base_url = "http://api.travis-ci.org/builds/$build_id";
16print "Retrieving $base_url\n";
17
18my $resp = ( my $ua = HTTP::Tiny->new )->get( $base_url );
19die "Unable to retrieve $resp->{url}: $resp->{status}\n$resp->{content}\n\n"
20 unless $resp->{success};
21
22my @job_ids = ( map
23 { ($_->{id}||'') =~ /^([0-9]+)$/ }
24 @{( eval { decode_json( $resp->{content} )->{matrix} } || [] )}
25) or die "Unable to find any job ids:\n$resp->{content}\n\n";
26
27my $dir = "TravisCI_build_$build_id";
28
29mkdir $dir
30 unless -d $dir;
31
32for my $job_id (@job_ids) {
33 my $log_url = "http://api.travis-ci.org/jobs/$job_id/log.txt";
34 my $dest_fn = "$dir/job_$job_id.log";
35
36 print "Retrieving $log_url into $dest_fn\n";
37
38 $resp = $ua->mirror( $log_url, $dest_fn );
39 warn "Error retrieving $resp->{url}: $resp->{status}\n$resp->{content}\n\n"
40 unless $resp->{success};
41}