| 1 | package ShipIt::Step::JenkinsCheck; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | ▶ | use base qw/ ShipIt::Step /; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use JSON qw/ decode_json /; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Try::Tiny; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use ShipIt::Util qw/ $term /; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | our $VERSION = '0.01'; | |||||||||||||
| 13 | |||||||||||||||
| 14 | 0 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 15 | 0 | my ($self, $conf) = @_; | |||||||||||||
| 16 | 0 | $self->{url} = $conf->value('JenkinsCheck.url'); | |||||||||||||
| 17 | 0 | $self->{jobs} = [ split /,/, $conf->value('JenkinsCheck.jobs') ]; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 0 | ▶ | die "No Jenkins URL specified" unless $self->{url}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | 0 | ▶ | die "No Jenkins jobs specified" unless @{ $self->{jobs} }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 21 | 0 | return; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | # Is really a class method. | ||||||||||||||
| 25 | 0 | ▶ | sub check_tests { | ||||||||||||
|
Subroutine
check_tests: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 26 | 0 | my ($self, $jenkins, @jobs) = @_; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 0 | my $ua = LWP::UserAgent->new(); | |||||||||||||
| 29 | 0 | my $response = $ua->get("$jenkins/api/json"); | |||||||||||||
| 30 | 0 | ▶ | die $response->status_line unless $response->is_success; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | my $obj = decode_json($response->decoded_content); | |||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | my %jobs = map { $_->{name} => $_->{color} } @{ $obj->{jobs} }; | |||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | my @errors; | |||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | foreach my $j (@jobs) { | |||||||||||||
| 39 | 0 | ▶ | if (!defined($jobs{$j})) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 40 | 0 | push @errors, "$j is not being tested by your Jenkins at $jenkins"; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | elsif ($jobs{$j} !~ /^blue|blue_anime$/) { | ||||||||||||||
| 43 | 0 | push @errors, "$j has status ".$jobs{$j}; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 0 | return @errors; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | ▶ | sub run { | ||||||||||||
|
Subroutine
run: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||
| 51 | 0 | my ($self, $state) = @_; | |||||||||||||
| 52 | 0 | my @results; | |||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | ▶ | try { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 55 | 0 | @results = $self->check_tests($self->{url}, @{ $self->{jobs} }); | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | 0 | ▶ | catch { | ||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||
| 58 | 0 | my $err = $_; | |||||||||||||
| 59 | 0 | while (1) { | |||||||||||||
| 60 | 0 | my $line = $term->readline("Jenkins check failed with $err, continue build? (y/n)"); | |||||||||||||
| 61 | 0 | ▶ | die "build aborted" if $line =~ /^n/i; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 0 | ▶ | last if $line =~ /^y/i; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | } | ||||||||||||||
| 64 | 0 | }; | |||||||||||||
| 65 | |||||||||||||||
| 66 | 0 | ▶ | unless (@results) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 0 | print "Jenkins reports all your tests to be passing.\n"; | |||||||||||||
| 68 | 0 | return; | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 0 | foreach my $r (@results) { | |||||||||||||
| 72 | 0 | print "$r\n"; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 0 | while (1) { | |||||||||||||
| 76 | 0 | my $line = $term->readline("Jenkins reports trouble, continue build? (y/n)"); | |||||||||||||
| 77 | 0 | ▶ | die "build aborted" if $line =~ /^n/i; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 78 | 0 | ▶ | last if $line =~ /^y/i; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | } | ||||||||||||||
| 80 | 0 | return; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | |||||||||||||||
| 84 | 1 | 1; | |||||||||||||
| 85 | __END__ | ||||||||||||||