| 1 | package Ukigumo::Agent::Dispatcher; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Amon2::Web::Dispatcher::RouterBoom; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Ukigumo::Agent::Manager; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Data::Validator; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | get '/' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | my $c = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | $c->render( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 'index.tt' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | children => $c->manager->children, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | job_queue => $c->manager->job_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | server_url => $c->manager->server_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | work_dir => $c->manager->work_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | max_children => $c->manager->max_children, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | timeout => $c->manager->timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ignore_github_tags => $c->manager->ignore_github_tags, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | force_git_url => $c->manager->force_git_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | cleanup_cycle => $c->manager->cleanup_cycle, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | my $rule = Data::Validator->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | repository => { isa => 'Str' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | branch => { isa => 'Str' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | )->with('NoThrow'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | post '/api/v0/enqueue' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $c = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $args = $rule->validate(+{%{$c->req->parameters}}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($rule->has_errors) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $errors = $rule->clear_errors(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $res = $c->render_json({errors => $errors}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $res->code(400); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $c->manager->register_job($args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | return $c->render_json(+{}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | post '/api/github_hook' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $c = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $c->logger->infof("payload: %s", $c->req->param('payload')); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $payload = from_json $c->req->param('payload'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (!$payload->{deleted} and my $ref = $payload->{ref}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $payload->{"deleted"} and my $ref = $payload->{"ref"}
MC/DC0%0/2
not $payload->{"deleted"} and my $ref = $payload->{"ref"}
not $payload->{"deleted"}
my $ref = $payload->{"ref"}
Truth table0%0/3
not(A) and B
A= not $payload->{"deleted"}B= my $ref = $payload->{"ref"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # TODO How to pass commit id? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # my @commits = @{$payload->{commits}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # ... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # commit => $commits[$#commits]->{id}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $repo_url = $payload->{repository}->{url}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($c->manager->force_git_url) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # From: https://github.com/tokuhirom/plenv.git | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # To: git@github.com:tokuhirom/plenv.git | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $repo_url =~ s!\Ahttps?://([^/]+)/!git\@$1:!; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | my $branch; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ($ref =~ s!\Arefs/heads/!!) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $branch = $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ▶ | elsif ($ref =~ s!\Arefs/tags/!! && !$c->manager->ignore_github_tags) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ref =~ s[\Arefs/tags/][] and not $c->manager->ignore_github_tags
MC/DC0%0/2
$ref =~ s[\Arefs/tags/][] and not $c->manager->ignore_github_tags
$ref =~ s[\Arefs/tags/][]
not $c->manager->ignore_github_tags
Truth table0%0/3
A and not(B)
A= $ref =~ s[\Arefs/tags/][]B= not $c->manager->ignore_github_tags
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $tag = $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($branch || $tag) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$branch or $tag
MC/DC0%0/2
$branch or $tag
$branch
$tag
Truth table0%0/3
A or B
A= $branchB= $tag
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | $args = +{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | repository => $repo_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | branch => $branch || $tag, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | compare_url => $payload->{compare} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | repository_owner => $payload->{repository}->{owner}->{name} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | repository_name => $payload->{repository}->{name} || '', | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$branch || $tag
$payload->{'compare'} || ''
$payload->{'repository'}{'owner'}{'name'} || ''
$payload->{'repository'}{'name'} || ''
MC/DC0%0/2
$branch || $tag
$branch
$tag
MC/DC0%0/1
$payload->{'compare'} || ''
$payload->{'compare'}
MC/DC0%0/1
$payload->{'repository'}{'owner'}{'name'} || ''
$payload->{'repository'}{'owner'}{'name'}
MC/DC0%0/1
$payload->{'repository'}{'name'} || ''
$payload->{'repository'}{'name'}
Truth table0%0/3
A || B
A= $branchB= $tag
Truth table0%0/2
A
A= $payload->{'compare'}
Truth table0%0/2
A
A= $payload->{'repository'}{'owner'}{'name'}
Truth table0%0/2
A
A= $payload->{'repository'}{'name'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if (my $e = $@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $c->logger->warnf("An error occured: %s", $e); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $res = $c->render_json({errors => $e}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $res->code(400); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($args) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $c->manager->register_job($args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return $c->render_json($args || +{}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args || {}
MC/DC0%0/1
$args || {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||