Github.pm

filter: Statementstmt 22.0% 108 / 491 Branchbran 0.0% 0 / 146 Conditioncond 0.0% 0 / 110 MC/DCmcdc 0.0% 0 / 66 Subroutinesub 28.8% 34 / 118 Podpod 61.8% 34 / 55 totaltotal 17.8% 176 / 986 SCAR 94.0
CC
138
Cov
14%
protect_branch
110.0
http_get
90.0
__ANON__
72.0
CRAP 12058.6
↑ Summary Github/Repository.pm »
1 package Net::Async::Github;
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 our $VERSION = '0.010';
7 1 our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
8  
9 1 ▶use parent qw(IO::Async::Notifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶no indirect;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =encoding utf8
15  
16 =head1 NAME
17  
18 Net::Async::Github - support for the L<https://github.com> REST API with L<IO::Async>
19  
20 =head1 SYNOPSIS
21  
22 use IO::Async::Loop;
23 use Net::Async::Github;
24 my $loop = IO::Async::Loop->new;
25 $loop->add(
26 my $gh = Net::Async::Github->new(
27 token => '...',
28 )
29 );
30 # Give 'secret_team' pull access to all private repos
31 $gh->repos(visibility => 'private')
32 ->grant_team(secret_team => 'pull')
33 ->await;
34  
35 =head1 DESCRIPTION
36  
37 This is a basic wrapper for Github's API.
38  
39 =cut
40  
41 1 ▶no indirect;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 1 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use Dir::Self;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use URI::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 1 ▶use Cache::LRU;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 1 ▶use Ryu::Async;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Ryu::Observable;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use Net::Async::WebSocket::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 1 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 1 ▶use Net::Async::Github::Branch;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 ▶use Net::Async::Github::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 1 ▶use Net::Async::Github::Team;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 1 ▶use Net::Async::Github::Plan;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use Net::Async::Github::PullRequest;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶use Net::Async::Github::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 1 ▶use Net::Async::Github::RateLimit;
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 1 my $json = JSON::MaybeXS->new;
71  
72 =head1 METHODS
73  
74 =head2 current_user
75  
76 Returns information about the current user.
77  
78 my $user = $gh->current_user->get;
79 printf "User [%s] has %d public repos and was last updated on %s%s\n",
80 $user->login, $user->public_repos, $user->updated_at->to_string
81  
82 Resolves to a L<Net::Async::Github::User> instance.
83  
84 =cut
85  
86 sub current_user {
87 0 ▶ my ($self, %args) = @_;
Subroutine current_user: not called CC=1 SCAR=6.9
Pod documented
88 0 $self->validate_args(%args);
89 $self->http_get(
90 uri => $self->endpoint('current_user')
91 )->transform(
92 done => sub {
93 Net::Async::Github::User->new(
94 0 ▶ %{$_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 github => $self,
96 )
97 }
98 )
99 0 }
100  
101 =head2 configure
102  
103 Accepts the following optional named parameters:
104  
105 =over 4
106  
107 =item * C<token> - the Github API token
108  
109 =item * C<endpoints> - hashref of L<RFC6570|https://tools.ietf.org/html/rfc6570>-compliant URL mappings
110  
111 =item * C<http> - an HTTP client compatible with the L<Net::Async::HTTP> API
112  
113 =item * C<mime_type> - the MIME type to use as the C<Accept> header for requests
114  
115 =item * C<page_cache_size> - number of GET responses to cache. Defaults to 1000, set to 0 to disable.
116  
117 =item * C<timeout> - How long in seconds to wait before giving up on a request. Defaults to 60. If set to 0, then no timeout will take place.
118  
119 =back
120  
121 B< You probably just want C<token> >, defaults should be fine for the
122 other settings.
123  
124 If you're creating a large number of instances, you can avoid
125 some disk access overhead by passing C<endpoints> from an existing
126 instance to the constructor for a new instance.
127  
128 =cut
129  
130 sub configure {
131 0 ▶ my ($self, %args) = @_;
Subroutine configure: not called CC=2 SCAR=17.9
Pod documented
132 0 for my $k (grep exists $args{$_}, qw(token endpoints api_key http base_uri mime_type page_cache_size timeout)) {
133 0 $self->{$k} = delete $args{$k};
134 }
135 0 $self->SUPER::configure(%args);
136 }
137  
138 =head2 reopen
139  
140 Reopens the given PR.
141  
142 Expects the following named parameters:
143  
144 =over 4
145  
146 =item * owner - which user or organisation owns this PR
147  
148 =item * repo - which repo it's for
149  
150 =item * id - the pull request ID
151  
152 =back
153  
154 Resolves to the current status.
155  
156 =cut
157  
158 sub reopen {
159 0 ▶ my ($self, %args) = @_;
Subroutine reopen: not called CC=2 SCAR=17.9
Pod documented
160 0 die "needs $_" for grep !$args{$_}, qw(owner repo id);
161 0 $self->validate_args(%args);
162 0 my $uri = URI->new($self->base_uri);
163 $uri->path(
164 join '/', 'repos', $args{owner}, $args{repo}, 'pulls', $args{id}
165 0 );
166 0 $self->http_patch(
167 uri => $uri,
168 data => {
169 state => 'open',
170 },
171 )
172 }
173  
174 =head2 pull_request
175  
176 Returns information about the given PR.
177  
178 Expects the following named parameters:
179  
180 =over 4
181  
182 =item * owner - which user or organisation owns this PR
183  
184 =item * repo - which repo it's for
185  
186 =item * id - the pull request ID
187  
188 =back
189  
190 Resolves to the current status.
191  
192 =cut
193  
194 sub pull_request {
195 0 ▶ my ($self, %args) = @_;
Subroutine pull_request: not called CC=2 SCAR=17.9
Pod documented
196 0 die "needs $_" for grep !$args{$_}, qw(owner repo id);
197 0 $self->validate_args(%args);
198 0 my $uri = $self->base_uri;
199 $uri->path(
200 join '/', 'repos', $args{owner}, $args{repo}, 'pulls', $args{id}
201 0 );
202 0 $log->tracef('Check Github pull request via URI %s', "$uri");
203 $self->http_get(
204 uri => $uri,
205 )->transform(
206 done => sub {
207 0 ▶ $log->tracef('Github PR data was ', $_[0]);
Subroutine __ANON__: not called CC=1 SCAR=6.9
208 Net::Async::Github::PullRequest->new(
209 0 %{$_[0]},
210 github => $self,
211 )
212 }
213 )
214 0 }
215  
216 # Provide an alias for anyone relying on previous name
217 1 *pr = *pull_request;
218  
219 =head2 pull_requests
220  
221 Returns information of all PRs of given repository.
222  
223 Expects the following named parameters:
224  
225 =over 4
226  
227 =item * C<owner> - which user or organisation owns this PR
228  
229 =item * C<repo> - the repository this pull request is for
230  
231 =back
232  
233 Returns a L<Ryu::Source> instance, this will emit a L<Net::Async::Github::PullRequest>
234 instance for each found repository.
235  
236 =cut
237  
238 sub pull_requests {
239 0 ▶ my ($self, %args) = @_;
Subroutine pull_requests: not called CC=1 SCAR=6.9
Pod documented
240 0 $self->validate_args(%args);
241 $self->api_get_list(
242 endpoint => 'pull_request',
243 endpoint_args => {
244 owner => $args{owner},
245 repo => $args{repo},
246 },
247 0 class => 'Net::Async::Github::PullRequest'
248 );
249 }
250  
251 # Provide an alias for anyone relying on previous name
252 1 *prs = *pull_requests;
253  
254 sub teams {
255 0 ▶ my ($self, %args) = @_;
Subroutine teams: not called CC=1 SCAR=6.9
Pod undocumented
256 0 $self->validate_args(%args);
257 $self->api_get_list(
258 0 uri => $self->endpoint('team', org => $args{organisation}),
259 class => 'Net::Async::Github::Team',
260 )
261 }
262  
263 sub Net::Async::Github::Repository::branches {
264 0 ▶ my ($self, %args) = @_;
Subroutine branches: not called CC=1 SCAR=6.9
Pod undocumented
265 0 my $gh = $self->github;
266 0 $gh->validate_args(%args);
267 0 $gh->api_get_list(
268 uri => $self->branches_url->process,
269 class => 'Net::Async::Github::Branch',
270 )
271 }
272  
273 sub Net::Async::Github::Repository::grant_team {
274 0 ▶ my ($self, %args) = @_;
Subroutine grant_team: not called CC=1 SCAR=6.9
Pod undocumented
275 0 my $gh = $self->github;
276 0 $gh->validate_args(%args);
277 $self->github->http_put(
278 uri => $self->github->endpoint(
279 'team_repo',
280 team => $args{team},
281 owner => $self->owner->{login},
282 repo => $self->name,
283 ),
284 data => {
285 permission => $args{permission},
286 },
287 )
288 0 }
289  
290 =head2 create_branch
291  
292 Creates a new branch.
293  
294 Takes the following named parameters:
295  
296 =over 4
297  
298 =item * C<owner> - which organisation owns the target repository
299  
300 =item * C<repo> - the repository to raise the PR against
301  
302 =item * C<branch> - new branch name that will be created
303  
304 =item * C<sha> - the SHA1 value for this branch
305  
306 =back
307  
308 =cut
309  
310 sub create_branch {
311 0 ▶ my ($self, %args) = @_;
Subroutine create_branch: not called CC=1 SCAR=6.9
Pod documented
312 0 $self->validate_args(%args);
313 $self->http_post(
314 uri => $self->endpoint(
315 'git_refs_create',
316 owner => $args{owner},
317 repo => $args{repo},
318 ),
319 data => {
320 ref => "refs/heads/$args{branch}",
321 sha => $args{sha}
322 },
323 )
324 0 }
325  
326  
327 =head2 update_ref
328  
329 Update a reference to a new commit
330  
331 Takes the following named parameters:
332  
333 =over 4
334  
335 =item * C<owner> - which organisation owns the target repository
336  
337 =item * C<repo> - the repository to raise the PR against
338  
339 =item * C<ref> - ref name that we are updating.
340  
341 =item * C<sha> - the SHA1 value of comment that the ref will point to
342  
343 =item * C<force> - force update ref even if it is not fast-forward if it is true.
344  
345 =back
346  
347 =cut
348  
349 sub update_ref {
350 0 ▶ my ($self, %args) = @_;
Subroutine update_ref: not called CC=2 SCAR=17.9
Pod documented
351 0 $self->validate_args(%args);
352 $self->http_patch(
353 uri => $self->endpoint(
354 'git_refs',
355 owner => $args{owner},
356 repo => $args{repo},
357 category => 'heads',
358 ref => $args{ref},
359 ),
360 data => {
361 sha => $args{sha},
362 0 ▶ force => ($args{force} ? JSON->true : JSON->false)
Branch: 1 branch
BranchTrueFalseTotal
$args{'force'} ? : 0 0 0
363 },
364 )
365 }
366  
367 =head2 create_pr
368  
369 Creates a new pull request.
370  
371 Takes the following named parameters:
372  
373 =over 4
374  
375 =item * C<owner> - which organisation owns the target repository
376  
377 =item * C<repo> - the repository to raise the PR against
378  
379 =item * C<head> - head commit starting point, typically the latest commit on your fork's branch
380  
381 =item * C<base> - base commit this PR applies changes to typically you'd want the target repo C<master>
382  
383 =back
384  
385 =cut
386  
387 sub create_pr {
388 0 ▶ my ($self, %args) = @_;
Subroutine create_pr: not called CC=2 SCAR=17.9
Pod documented
389 0 $self->validate_args(%args);
390 $self->http_post(
391 uri => $self->endpoint(
392 'pull_request',
393 owner => $args{owner},
394 repo => $args{repo},
395 ),
396 data => {
397 head => $args{head},
398 base => $args{base},
399 title => $args{title},
400 0 ▶ $args{body} ? (body => $args{body}) : (),
Branch: 1 branch
BranchTrueFalseTotal
$args{'body'} ? : 0 0 0
401 },
402 )
403 }
404  
405 =head2 create_commit
406  
407 Creates an empty commit. Can be used to simulate C<git commit --allow-empty>
408 or to create a merge commit from multiple heads.
409  
410 Takes the following named parameters:
411  
412 =over 4
413  
414 =item * C<owner> - which organisation owns the target repository
415  
416 =item * C<repo> - the repository to raise the PR against
417  
418 =item * C<message> - The commit message
419  
420 =item * C<tree> - The SHA of tree object that commit will point to
421  
422 =item * C<parents> - Arrayref that include the parents of the commit
423  
424 =back
425  
426 =cut
427  
428 sub create_commit {
429 0 ▶ my ($self, %args) = @_;
Subroutine create_commit: not called CC=1 SCAR=6.9
Pod documented
430 0 $self->validate_args(%args);
431 $self->http_post(
432 uri => $self->endpoint(
433 'commits',
434 owner => $args{owner},
435 repo => $args{repo},
436 ),
437 data => {
438 message => $args{message},
439 tree => $args{tree},
440 parents => $args{parents},
441 },
442 )
443 0 }
444  
445 # Example:
446 #
447 # $repo->protect_branch(
448 # branch => 'master',
449 # required_status_checks => {
450 # strict => 1,
451 # contexts => [
452 # '',
453 # ]
454 # },
455 # enforce_admins => 0,
456 # restrictions => {
457 # teams => [
458 # 'WRITE-Admin',
459 # ]
460 # }
461 sub Net::Async::Github::Repository::protect_branch {
462 0 ▶ my ($self, %args) = @_;
Subroutine protect_branch: not called CC=10 SCAR=47.0
Pod undocumented
463 0 my $gh = $self->github;
464 0 $gh->validate_args(%args);
465  
466 # Coërce the true/false values into something appropriate for JSON
467 0 $args{required_status_checks} = { %{$args{required_status_checks}} };
468 0 ▶ $_->{strict} = $_->{strict} ? JSON->true : JSON->false for $args{required_status_checks};
Branch: 1 branch
BranchTrueFalseTotal
$_->{'strict'} ? : 0 0 0
469 0 ▶ $args{enforce_admins} = $args{enforce_admins} ? JSON->true : JSON->false;
Branch: 1 branch
BranchTrueFalseTotal
$args{'enforce_admins'} ? : 0 0 0
470 0 ▶ $args{required_pull_request_reviews} //= undef;
Condition0%0/2
$args{"required_pull_request_reviews"} //= undef
l!l
00
MC/DC0%0/1
$args{"required_pull_request_reviews"} //= undef
$args{"required_pull_request_reviews"}
Truth table0%0/2
A
A= $args{"required_pull_request_reviews"}
Aresult
11
00
471 0 ▶ if($args{restrictions} //= undef) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"restrictions"} //= undef) 0 0 0
Condition0%0/2
$args{"restrictions"} //= undef
l!l
00
MC/DC0%0/1
$args{"restrictions"} //= undef
$args{"restrictions"}
Truth table0%0/2
A
A= $args{"restrictions"}
Aresult
11
00
472 0 ▶ $args{restrictions}{users} ||= [];
Condition0%0/2
$args{"restrictions"}{"users"} ||= []
l!l
00
MC/DC0%0/1
$args{"restrictions"}{"users"} ||= []
$args{"restrictions"}{"users"}
Truth table0%0/2
A
A= $args{"restrictions"}{"users"}
Aresult
11
00
473 0 ▶ $args{restrictions}{teams} ||= [];
Condition0%0/2
$args{"restrictions"}{"teams"} ||= []
l!l
00
MC/DC0%0/1
$args{"restrictions"}{"teams"} ||= []
$args{"restrictions"}{"teams"}
Truth table0%0/2
A
A= $args{"restrictions"}{"teams"}
Aresult
11
00
474 }
475  
476 $self->github->http_put(
477 uri => $self->github->endpoint(
478 'branch_protection',
479 owner => $self->owner->{login},
480 repo => $self->name,
481 branch => ($args{branch} // die 'need a branch'),
482 ),
483 data => {
484 map {;
485 0 $_ => $args{$_}
486 } grep {
487 0 ▶ exists $args{$_}
Condition0%0/2
$args{"branch"} // die("need a branch")
l!l
00
MC/DC0%0/1
$args{"branch"} // die("need a branch")
$args{"branch"}
Truth table0%0/2
A
A= $args{"branch"}
Aresult
11
00
488 } qw(
489 required_status_checks
490 enforce_admins
491 required_pull_request_reviews
492 restrictions
493 )
494 },
495 )
496 }
497  
498 sub Net::Async::Github::Repository::branch_protection {
499 0 ▶ my ($self, %args) = @_;
Subroutine branch_protection: not called CC=2 SCAR=17.9
Pod undocumented
500 0 my $gh = $self->github;
501 0 $gh->validate_args(%args);
502 $self->github->http_get(
503 uri => $self->github->endpoint(
504 'branch_protection',
505 owner => $self->owner->{login},
506 repo => $self->name,
507 0 ▶ branch => ($args{branch} // die 'need a branch'),
Condition0%0/2
$args{"branch"} // die("need a branch")
l!l
00
MC/DC0%0/1
$args{"branch"} // die("need a branch")
$args{"branch"}
Truth table0%0/2
A
A= $args{"branch"}
Aresult
11
00
508 ),
509 )
510 }
511  
512 sub Net::Async::Github::Repository::get_file {
513 0 ▶ my ($self, %args) = @_;
Subroutine get_file: not called CC=3 SCAR=24.8
Pod undocumented
514 0 my $gh = $self->github;
515 0 $gh->validate_args(%args);
516 $self->github->http_get(
517 uri => $self->github->endpoint(
518 'contents',
519 owner => $self->owner->{login},
520 repo => $self->name,
521 path => ($args{path} // die 'need a path'),
522 (exists $args{branch} ? (branch => $args{branch}) : ()),
523 ),
524 )->transform(
525 done => sub {
526 0 ▶ my ($result) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
527 0 ▶ if($result->{encoding} eq 'base64') {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'encoding'} eq 'base64') { } 0 0 0
528 return MIME::Base64::decode_base64($result->{content})
529 0 } else {
530 return $result->{content}
531 0 }
532 }
533 )
534 0 ▶}
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'branch'} ? : 0 0 0
Condition0%0/2
$args{"path"} // die("need a path")
l!l
00
MC/DC0%0/1
$args{"path"} // die("need a path")
$args{"path"}
Truth table0%0/2
A
A= $args{"path"}
Aresult
11
00
535  
536 0 ▶sub Net::Async::Github::PullRequest::owner { shift->{base}{repo}{owner}{login} }
Subroutine owner: not called CC=1 SCAR=6.9
Pod undocumented
537 0 ▶sub Net::Async::Github::PullRequest::repo { shift->{base}{repo}{name} }
Subroutine repo: not called CC=1 SCAR=6.9
Pod undocumented
538 0 ▶sub Net::Async::Github::PullRequest::branch_name { shift->{head}{ref} }
Subroutine branch_name: not called CC=1 SCAR=6.9
Pod undocumented
539  
540 sub Net::Async::Github::PullRequest::merge {
541 0 ▶ my ($self, %args) = @_;
Subroutine merge: not called CC=7 SCAR=40.3
Pod undocumented
542 0 my $gh = $self->github;
543 0 $gh->validate_args(%args);
544 0 ▶ die 'invalid owner' if ref $self->owner;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->owner 0 0 0
545 0 ▶ die 'invalid repo' if ref $self->repo;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->repo 0 0 0
546 0 ▶ die 'invalid id' if ref $self->id;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->id 0 0 0
547 my $uri = $gh->endpoint(
548 'pull_request_merge',
549 owner => $args{owner} // $self->owner,
550 repo => $args{repo} // $self->repo,
551 0 ▶ id => $args{id} // $self->number,
Condition0%0/9
$args{"owner"} // $self->owner
l!l&&r!l&&!r
000
$args{"repo"} // $self->repo
l!l&&r!l&&!r
000
$args{"id"} // $self->number
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"owner"} // $self->owner
$args{"owner"} $self->owner
MC/DC0%0/2
$args{"repo"} // $self->repo
$args{"repo"} $self->repo
MC/DC0%0/2
$args{"id"} // $self->number
$args{"id"} $self->number
Truth table0%0/3
A // B
A= $args{"owner"}B= $self->owner
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"repo"}B= $self->repo
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"id"}B= $self->number
ABresult
1X1
011
000
552 );
553 0 $log->infof('URI for PR merge is %s', "$uri");
554 $gh->http_put(
555 uri => $uri,
556 data => {
557 sha => $self->{head}{sha},
558 0 map { $_ => $args{$_} } grep { exists $args{$_} } qw(
559 commit_title
560 commit_message
561 sha
562 merge_method
563 admin_override
564 )
565 }
566 )
567 }
568  
569 sub Net::Async::Github::PullRequest::cleanup {
570 0 ▶ my ($self, %args) = @_;
Subroutine cleanup: not called CC=7 SCAR=40.3
Pod undocumented
571 0 my $gh = $self->github;
572 0 $gh->validate_args(%args);
573 0 ▶ die 'invalid owner' if ref $self->owner;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->owner 0 0 0
574 0 ▶ die 'invalid repo' if ref $self->repo;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->repo 0 0 0
575 0 ▶ die 'invalid id' if ref $self->id;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->id 0 0 0
576 my $uri = $gh->endpoint(
577 'git_refs',
578 category => 'heads',
579 owner => $args{owner} // $self->{head}{repo}{owner}{login},
580 repo => $args{repo} // $self->{head}{repo}{name},
581 0 ▶ ref => $args{ref} // $self->branch_name,
Condition0%0/9
$args{"owner"} // $self->{"head"}{"repo"}{"owner"}{"login"}
l!l&&r!l&&!r
000
$args{"repo"} // $self->{"head"}{"repo"}{"name"}
l!l&&r!l&&!r
000
$args{"ref"} // $self->branch_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"owner"} // $self->{"head"}{"repo"}{"owner"}{"login"}
$args{"owner"} $self->{"head"}{"repo"}{"owner"}{"login"}
MC/DC0%0/2
$args{"repo"} // $self->{"head"}{"repo"}{"name"}
$args{"repo"} $self->{"head"}{"repo"}{"name"}
MC/DC0%0/2
$args{"ref"} // $self->branch_name
$args{"ref"} $self->branch_name
Truth table0%0/3
A // B
A= $args{"owner"}B= $self->{"head"}{"repo"}{"owner"}{"login"}
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"repo"}B= $self->{"head"}{"repo"}{"name"}
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $args{"ref"}B= $self->branch_name
ABresult
1X1
011
000
582 );
583 0 $log->infof('URI for PR delete is %s', "$uri");
584 0 $gh->http_delete(
585 uri => $uri,
586 )
587 }
588  
589 sub repos {
590 0 ▶ my ($self, %args) = @_;
Subroutine repos: not called CC=4 SCAR=30.0
Pod undocumented
591 0 ▶ if(my $user = delete $args{owner}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $user = delete $args{'owner'}) { } 0 0 0
592 0 $self->validate_owner_name($user);
593 $self->api_get_list(
594 endpoint => 'user_repositories',
595 endpoint_args => {
596 user => $user,
597 0 ▶ visibility => $args{visibility} // 'all',
Condition0%0/2
$args{"visibility"} // "all"
l!l
00
MC/DC0%0/1
$args{"visibility"} // "all"
$args{"visibility"}
Truth table0%0/2
A
A= $args{"visibility"}
Aresult
11
00
598 },
599 class => 'Net::Async::Github::Repository',
600 )
601 } else {
602 $self->api_get_list(
603 endpoint => 'current_user_repositories',
604 endpoint_args => {
605 0 ▶ visibility => $args{visibility} // 'all',
Condition0%0/2
$args{"visibility"} // "all"
l!l
00
MC/DC0%0/1
$args{"visibility"} // "all"
$args{"visibility"}
Truth table0%0/2
A
A= $args{"visibility"}
Aresult
11
00
606 },
607 class => 'Net::Async::Github::Repository',
608 )
609 }
610 }
611  
612 sub repo {
613 0 ▶ my ($self, %args) = @_;
Subroutine repo: not called CC=3 SCAR=24.8
Pod documented
614 0 ▶ die 'need an owner name' unless my $owner = delete $args{owner};
Branch: 1 branch
BranchTrueFalseTotal
unless my $owner = delete $args{"owner"} 0 0 0
615 0 ▶ die 'need a repo name' unless my $repo_name = delete $args{name};
Branch: 1 branch
BranchTrueFalseTotal
unless my $repo_name = delete $args{"name"} 0 0 0
616 0 $self->validate_owner_name($owner);
617 0 $self->validate_repo_name($repo_name);
618 $self->http_get(
619 uri => $self->endpoint(
620 repository => (
621 owner => $owner,
622 repo => $repo_name,
623 )
624 ),
625 )->transform(
626 done => sub {
627 0 ▶ $log->tracef('Github repo data was %s', $_[0]);
Subroutine __ANON__: not called CC=1 SCAR=6.9
628 Net::Async::Github::Repository->new(
629 0 %{$_[0]},
630 github => $self,
631 )
632 }
633 )
634 0 }
635  
636 =head2 user
637  
638 Returns information about the given user.
639  
640 =cut
641  
642 sub user {
643 0 ▶ my ($self, $user, %args) = @_;
Subroutine user: not called CC=1 SCAR=6.9
Pod documented
644 0 $self->validate_owner_name($user);
645 $self->http_get(
646 uri => $self->endpoint(
647 'user',
648 user => $user
649 ),
650 )->transform(
651 done => sub {
652 Net::Async::Github::User->new(
653 0 ▶ %{$_[0]},
Subroutine __ANON__: not called CC=1 SCAR=6.9
654 github => $self,
655 )
656 }
657 )
658 0 }
659  
660 =head2 users
661  
662 Iterates through all users. This is a good way to exhaust your 5000-query
663 ratelimiting quota.
664  
665 =cut
666  
667 sub users {
668 0 ▶ my ($self, %args) = @_;
Subroutine users: not called CC=1 SCAR=6.9
Pod documented
669 0 $self->validate_args(%args);
670 0 $self->api_get_list(
671 uri => '/users',
672 class => 'Net::Async::Github::User',
673 )
674 }
675  
676 =head2 head
677  
678 Identifies the head version for this branch.
679  
680 Requires the following named parameters:
681  
682 =over 4
683  
684 =item * owner - which organisation or person owns the repo
685  
686 =item * repo - the repository name
687  
688 =item * branch - which branch to check
689  
690 =back
691  
692 =cut
693  
694 sub head {
695 0 ▶ my ($self, %args) = @_;
Subroutine head: not called CC=2 SCAR=17.9
Pod documented
696 0 die "needs $_" for grep !$args{$_}, qw(owner repo branch);
697 0 $self->validate_args(%args);
698 0 my $uri = $self->base_uri;
699 $uri->path(
700 join '/', 'repos', $args{owner}, $args{repo}, qw(git refs heads), $args{branch}
701 0 );
702 0 $self->http_get(
703 uri => $uri
704 )
705 }
706  
707 =head2 update
708  
709 =cut
710  
711 sub update {
712 0 ▶ my ($self, %args) = @_;
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
713 0 die "needs $_" for grep !$args{$_}, qw(owner repo branch head);
714 0 $self->validate_branch_name($args{branch});
715 0 my $uri = $self->base_uri;
716 $uri->path(
717 0 join '/', 'repos', $args{owner}, $args{repo}, qw(merges)
718 );
719 $self->http_post(
720 uri => $uri,
721 data => {
722 head => $args{head},
723 base => $args{branch},
724 commit_message => "Merge branch 'master' into " . $args{branch},
725 },
726 )
727 0 }
728  
729 =head2 core_rate_limit
730  
731 Returns a L<Net::Async::Github::RateLimit::Core> instance which can track rate limits.
732  
733 =cut
734  
735 sub core_rate_limit {
736 0 ▶ my ($self) = @_;
Subroutine core_rate_limit: not called CC=2 SCAR=11.9
Pod documented
737 0 ▶ $self->{core_rate_limit} //= do {
Condition0%0/3
$self->{"core_rate_limit"} //= do { my $rl = "Net::Async::Github::RateLimit::Core"->new("limit", "Ryu::Observable"->new(undef), "remaining", "Ryu::Observable"->new(undef), "reset", "Ryu::Observable"->new(undef)); retain_future($self->http_get("uri", $self->endpoint("rate_limit"))->on_done(sub { my $data = shift(); $Net::Async::Github::log->tracef("Github rate limit response was %s", $data); $rl->reset->set_numeric($data->{"resources"}{"core"}{"reset"}); $rl->limit->set_numeric($data->{"resources"}{"core"}{"limit"}); $rl->remaining->set_numeric($data->{"resources"}{"core"}{"remaining"}); } )); $rl }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"core_rate_limit"} //= do { my $rl = "Net::Async::Github::RateLimit::Core"->new("limit", "Ryu::Observable"->new(undef), "remaining", "Ryu::Observable"->new(undef), "reset", "Ryu::Observable"->new(undef)); retain_future($self->http_get("uri", $self->endpoint("rate_limit"))->on_done(sub { my $data = shift(); $Net::Async::Github::log->tracef("Github rate limit response was %s", $data); $rl->reset->set_numeric($data->{"resources"}{"core"}{"reset"}); $rl->limit->set_numeric($data->{"resources"}{"core"}{"limit"}); $rl->remaining->set_numeric($data->{"resources"}{"core"}{"remaining"}); } )); $rl }
$self->{"core_rate_limit"} do { my $rl = "Net::Async::Github::RateLimit::Core"->new("limit", "Ryu::Observable"->new(undef), "remaining", "Ryu::Observable"->new(undef), "reset", "Ryu::Observable"->new(undef)); retain_future($self->http_get("uri", $self->endpoint("rate_limit"))->on_done(sub { my $data = shift(); $Net::Async::Github::log->tracef("Github rate limit response was %s", $data); $rl->reset->set_numeric($data->{"resources"}{"core"}{"reset"}); $rl->limit->set_numeric($data->{"resources"}{"core"}{"limit"}); $rl->remaining->set_numeric($data->{"resources"}{"core"}{"remaining"}); } )); $rl }
Truth table0%0/3
A //= B
A= $self->{"core_rate_limit"}B= do { my $rl = "Net::Async::Github::RateLimit::Core"->new("limit", "Ryu::Observable"->new(undef), "remaining", "Ryu::Observable"->new(undef), "reset", "Ryu::Observable"->new(undef)); retain_future($self->http_get("uri", $self->endpoint("rate_limit"))->on_done(sub { my $data = shift(); $Net::Async::Github::log->tracef("Github rate limit response was %s", $data); $rl->reset->set_numeric($data->{"resources"}{"core"}{"reset"}); $rl->limit->set_numeric($data->{"resources"}{"core"}{"limit"}); $rl->remaining->set_numeric($data->{"resources"}{"core"}{"remaining"}); } )); $rl }
ABresult
1X1
011
000
738 1 ▶ use Variable::Disposition qw(retain_future);
Subroutine BEGIN: called CC=1 SCAR=0.0
739 1 ▶ use namespace::clean qw(retain_future);
Subroutine BEGIN: called CC=1 SCAR=0.0
740 0 my $rl = Net::Async::Github::RateLimit::Core->new(
741 limit => Ryu::Observable->new(undef),
742 remaining => Ryu::Observable->new(undef),
743 reset => Ryu::Observable->new(undef),
744 );
745 retain_future(
746 $self->http_get(
747 uri => $self->endpoint('rate_limit')
748 )->on_done(sub {
749 0 ▶ my $data = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
750 0 $log->tracef("Github rate limit response was %s", $data);
751 0 $rl->reset->set_numeric($data->{resources}{core}{reset});
752 0 $rl->limit->set_numeric($data->{resources}{core}{limit});
753 0 $rl->remaining->set_numeric($data->{resources}{core}{remaining});
754 })
755 0 );
756 0 $rl;
757 }
758 }
759  
760 =head2 rate_limit
761  
762 =cut
763  
764 sub rate_limit {
765 0 ▶ my ($self) = @_;
Subroutine rate_limit: not called CC=1 SCAR=6.9
Pod documented
766 $self->http_get(
767 uri => $self->endpoint('rate_limit')
768 )->transform(
769 done => sub {
770 Net::Async::Github::RateLimit->new(
771 0 ▶ %{$_[0]}
Subroutine __ANON__: not called CC=1 SCAR=6.9
772 )
773 }
774 )
775 0 }
776  
777 =head1 METHODS - Internal
778  
779 The following methods are used internally. They're not expected to be
780 useful for external callers.
781  
782 =head2 api_key
783  
784 =cut
785  
786 0 ▶sub api_key { shift->{api_key} }
Subroutine api_key: not called CC=1 SCAR=6.9
Pod documented
787  
788 =head2 token
789  
790 =cut
791  
792 0 ▶sub token { shift->{token} }
Subroutine token: not called CC=1 SCAR=6.9
Pod documented
793  
794 =head2 endpoints
795  
796 Returns an accessor for the endpoints data. This is a hashref containing URI
797 templates, used by L</endpoint>.
798  
799 =cut
800  
801 sub endpoints {
802 0 ▶ my ($self) = @_;
Subroutine endpoints: not called CC=3 SCAR=24.8
Pod documented
803 0 ▶ $self->{endpoints} ||= do {
Condition0%0/3
$self->{"endpoints"} ||= do { my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json"); $path = Path::Tiny::path(File::ShareDir::dist_file("Net-Async-Github", "endpoints.json")) unless $path->exists; $json->decode($path->slurp_utf8) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"endpoints"} ||= do { my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json"); $path = Path::Tiny::path(File::ShareDir::dist_file("Net-Async-Github", "endpoints.json")) unless $path->exists; $json->decode($path->slurp_utf8) }
$self->{"endpoints"} do { my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json"); $path = Path::Tiny::path(File::ShareDir::dist_file("Net-Async-Github", "endpoints.json")) unless $path->exists; $json->decode($path->slurp_utf8) }
Truth table0%0/3
A ||= B
A= $self->{"endpoints"}B= do { my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json"); $path = Path::Tiny::path(File::ShareDir::dist_file("Net-Async-Github", "endpoints.json")) unless $path->exists; $json->decode($path->slurp_utf8) }
ABresult
1X1
011
000
804 0 my $path = Path::Tiny::path(__DIR__)->parent(3)->child('share/endpoints.json');
805 0 ▶ $path = Path::Tiny::path(
Branch: 1 branch
BranchTrueFalseTotal
unless $path->exists 0 0 0
806 File::ShareDir::dist_file(
807 'Net-Async-Github',
808 'endpoints.json'
809 )
810 ) unless $path->exists;
811 0 $json->decode($path->slurp_utf8)
812 };
813 }
814  
815 =head2 endpoint
816  
817 Expands the selected URI via L<URI::Template>. Each item is defined in our C< endpoints.json >
818 file.
819  
820 Returns a L<URI> instance.
821  
822 =cut
823  
824 sub endpoint {
825 0 ▶ my ($self, $endpoint, %args) = @_;
Subroutine endpoint: not called CC=1 SCAR=6.9
Pod documented
826 URI::Template->new(
827 0 $self->endpoints->{$endpoint . '_url'}
828 )->process(%args);
829 }
830  
831 =head2 http
832  
833 Accessor for the HTTP client object. Will load and instantiate a L<Net::Async::HTTP> instance
834 if necessary.
835  
836 Actual HTTP implementation is not guaranteed, and the default is likely to change in future.
837  
838 =cut
839  
840 sub http {
841 0 ▶ my ($self) = @_;
Subroutine http: not called CC=3 SCAR=24.8
Pod documented
842 0 ▶ $self->{http} ||= do {
Condition0%0/3
$self->{"http"} ||= do { require Net::Async::HTTP; $self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "max_connections_per_host", $self->connections_per_host, "pipeline", 1, "max_in_flight", 4, "decode_content", 1, "user_agent", "Mozilla/4.0 (perl; Net::Async::Github; TEAM\@cpan.org)", $self->timeout ? ("timeout", $self->timeout) : ())); $ua }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"http"} ||= do { require Net::Async::HTTP; $self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "max_connections_per_host", $self->connections_per_host, "pipeline", 1, "max_in_flight", 4, "decode_content", 1, "user_agent", "Mozilla/4.0 (perl; Net::Async::Github; TEAM\@cpan.org)", $self->timeout ? ("timeout", $self->timeout) : ())); $ua }
$self->{"http"} do { require Net::Async::HTTP; $self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "max_connections_per_host", $self->connections_per_host, "pipeline", 1, "max_in_flight", 4, "decode_content", 1, "user_agent", "Mozilla/4.0 (perl; Net::Async::Github; TEAM\@cpan.org)", $self->timeout ? ("timeout", $self->timeout) : ())); $ua }
Truth table0%0/3
A ||= B
A= $self->{"http"}B= do { require Net::Async::HTTP; $self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "max_connections_per_host", $self->connections_per_host, "pipeline", 1, "max_in_flight", 4, "decode_content", 1, "user_agent", "Mozilla/4.0 (perl; Net::Async::Github; TEAM\@cpan.org)", $self->timeout ? ("timeout", $self->timeout) : ())); $ua }
ABresult
1X1
011
000
843 0 require Net::Async::HTTP;
844 0 ▶ $self->add_child(
Branch: 1 branch
BranchTrueFalseTotal
$self->timeout ? : 0 0 0
845 my $ua = Net::Async::HTTP->new(
846 fail_on_error => 1,
847 max_connections_per_host => $self->connections_per_host,
848 pipeline => 1,
849 max_in_flight => 4,
850 decode_content => 1,
851 user_agent => 'Mozilla/4.0 (perl; Net::Async::Github; TEAM@cpan.org)',
852 (
853 $self->timeout
854 ? (timeout => $self->timeout)
855 : ()
856 ),
857 )
858 );
859 0 $ua
860 }
861 }
862  
863 sub update_limiter {
864 0 ▶ my ($self) = @_;
Subroutine update_limiter: not called CC=2 SCAR=17.9
Pod undocumented
865 0 ▶ unless($self->{update_limiter}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"update_limiter"}) 0 0 0
866 # Any modification should wait for this to resolve first
867 $self->{update_limiter} = $self->loop->delay_future(
868 after => 1
869 )->on_ready(sub {
870 delete $self->{update_limiter}
871 0 ▶ });
Subroutine __ANON__: not called CC=1 SCAR=6.9
872 # Limit the next request - not this one
873 0 return Future->done;
874 }
875 0 return $self->{update_limiter};
876 }
877  
878 # Github ratelimit guidelines suggest max 1 request in parallel
879 # per user, with 1s between any state-modifying calls. Since this
880 # is part of their defined API, we don't expose this in L</configure>.
881 0 ▶sub connections_per_host { 4 }
Subroutine connections_per_host: not called CC=1 SCAR=6.9
Pod undocumented
882  
883 # Like connections, but for data modification - POST, PUT, PATCH etc.
884 0 ▶sub updates_per_host { 1 }
Subroutine updates_per_host: not called CC=1 SCAR=6.9
Pod undocumented
885  
886 =head2 timeout
887  
888 The parameter that will be used when create Net::Async::HTTP object. If it is undef, then a default value
889 60 seconds will be used. If it is 0, then Net::Async::HTTP will never timeout.
890  
891 =cut
892  
893 0 ▶sub timeout { shift->{timeout} //= 60 }
Subroutine timeout: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
+(shift())->{"timeout"} //= 60
l!l
00
MC/DC0%0/1
+(shift())->{"timeout"} //= 60
+(shift())->{"timeout"}
Truth table0%0/2
A
A= +(shift())->{"timeout"}
Aresult
11
00
894  
895 =head2 auth_info
896  
897 Returns authentication information used in the HTTP request.
898  
899 =cut
900  
901 sub auth_info {
902 0 ▶ my ($self) = @_;
Subroutine auth_info: not called CC=3 SCAR=24.8
Pod documented
903 0 ▶ if(my $key = $self->api_key) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = $self->api_key) 0 0 0
904 return (
905 0 user => $key,
906 pass => '',
907 );
908 }
909 0 ▶ if(my $token = $self->token) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $self->token) 0 0 0
910 return (
911 0 headers => {
912 Authorization => 'token ' . $token
913 }
914 )
915 }
916  
917 0 die "need some form of auth, try passing a token or api_key"
918 }
919  
920 =head2 mime_type
921  
922 Returns the MIME type used for requests. Currently defined by github in
923 L<https://developer.github.com/v3/media/> as C<application/vnd.github.v3+json>.
924  
925 =cut
926  
927 0 ▶sub mime_type { shift->{mime_type} //= 'application/vnd.github.v3+json' }
Subroutine mime_type: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
+(shift())->{"mime_type"} //= "application/vnd.github.v3+json"
l!l
00
MC/DC0%0/1
+(shift())->{"mime_type"} //= "application/vnd.github.v3+json"
+(shift())->{"mime_type"}
Truth table0%0/2
A
A= +(shift())->{"mime_type"}
Aresult
11
00
928  
929 =head2 base_uri
930  
931 The L<URI> for requests. Defaults to L<https://api.github.com>.
932  
933 =cut
934  
935 sub base_uri {
936 (
937 0 ▶ shift->{base_uri} //= URI->new('https://api.github.com')
Subroutine base_uri: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
+(shift())->{"base_uri"} //= "URI"->new("https://api.github.com")
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->{"base_uri"} //= "URI"->new("https://api.github.com")
+(shift())->{"base_uri"} "URI"->new("https://api.github.com")
Truth table0%0/3
A //= B
A= +(shift())->{"base_uri"}B= "URI"->new("https://api.github.com")
ABresult
1X1
011
000
938 )->clone
939 }
940  
941 =head2 http_get
942  
943 Performs an HTTP GET request.
944  
945 =cut
946  
947 sub http_get {
948 0 ▶ my ($self, %args) = @_;
Subroutine http_get: not called CC=9 SCAR=45.0
Pod documented
949 0 my %auth = $self->auth_info;
950  
951 0 ▶ if(my $hdr = delete $auth{headers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hdr = delete $auth{"headers"}) 0 0 0
952 0 ▶ $args{headers}{$_} //= $hdr->{$_} for keys %$hdr
Condition0%0/3
$args{"headers"}{$_} //= $hdr->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"headers"}{$_} //= $hdr->{$_}
$args{"headers"}{$_} $hdr->{$_}
Truth table0%0/3
A //= B
A= $args{"headers"}{$_}B= $hdr->{$_}
ABresult
1X1
011
000
953 }
954 0 ▶ $args{$_} //= $auth{$_} for keys %auth;
Condition0%0/3
$args{$_} //= $auth{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{$_} //= $auth{$_}
$args{$_} $auth{$_}
Truth table0%0/3
A //= B
A= $args{$_}B= $auth{$_}
ABresult
1X1
011
000
955  
956 0 my $uri = delete $args{uri};
957 0 $log->tracef("GET %s { %s }", $uri->as_string, \%args);
958 0 my $cached = $self->page_cache->get($uri->as_string);
959 0 ▶ if($cached) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cached) 0 0 0
960 0 $log->tracef("Had cached page data, etag %s and last modified %s", $cached->header('ETag'), $cached->header('Last-Modified'));
961 0 ▶ $args{headers}{'If-None-Match'} = $cached->header('ETag') if $cached->header('ETag');
Branch: 1 branch
BranchTrueFalseTotal
if $cached->header("ETag") 0 0 0
962 0 ▶ $args{headers}{'If-Modified-Since'} = $cached->header('Last-Modified') if $cached->header('Last-Modified');
Branch: 1 branch
BranchTrueFalseTotal
if $cached->header("Last-Modified") 0 0 0
963 }
964 $self->http->GET(
965 $uri,
966 %args,
967 )->on_fail(sub {
968 0 ▶ $log->tracef('Response failed for %s', "$uri");
Subroutine __ANON__: not called CC=1 SCAR=6.9
969 })->on_cancel(sub {
970 0 ▶ $log->tracef('Request cancelled for %s', "$uri");
Subroutine __ANON__: not called CC=1 SCAR=6.9
971 })->on_done(sub {
972 0 ▶ $log->tracef('Response received for %s', "$uri");
Subroutine __ANON__: not called CC=1 SCAR=6.9
973 })->then(sub {
974 0 ▶ my ($resp) = @_;
Subroutine __ANON__: not called CC=8 SCAR=42.8
975 0 $log->tracef("Github response: %s", $resp->as_string("\n"));
976 # If we had ratelimiting headers, apply them
977 0 for my $k (qw(Reset Limit Remaining)) {
978 0 ▶ if(defined(my $v = $resp->header('X-RateLimit-' . $k))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $resp->header('X-RateLimit-' . $k))) 0 0 0
979 0 my $method = lc $k;
980 0 $self->core_rate_limit->$method->set_numeric($v);
981 }
982 }
983  
984 0 ▶ if($cached && $resp->code == 304) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cached and $resp->code == 304) { } 0 0 0
elsif ($resp->is_success) { } 0 0 0
Condition0%0/3
$cached and $resp->code == 304
!ll&&!rl&&r
000
MC/DC0%0/2
$cached and $resp->code == 304
$cached $resp->code == 304
Truth table0%0/3
A and B
A= $cachedB= $resp->code == 304
ABresult
0X0
100
111
985 0 $resp = $cached;
986 0 $log->tracef("Using cached version of [%s] for %d byte response", $uri->as_string, $resp->content_length);
987 } elsif($resp->is_success) {
988 0 $log->tracef("Caching [%s] with %d byte response", $uri->as_string, $resp->content_length);
989 0 $self->page_cache->set($uri->as_string => $resp);
990 } else {
991 0 $log->tracef("Not caching [%s] due to status %d", $resp->code);
992 }
993  
994 0 ▶ return Future->done(
Branch: 1 branch
BranchTrueFalseTotal
if $resp->code == 204 0 0 0
995 { },
996 $resp
997 ) if $resp->code == 204;
998 0 ▶ return Future->done(
Branch: 1 branch
BranchTrueFalseTotal
if 3 == $resp->code / 100 0 0 0
999 { },
1000 $resp
1001 ) if 3 == ($resp->code / 100);
1002 try {
1003 0 return Future->done(
1004 $json->decode(
1005 $resp->decoded_content
1006 ),
1007 $resp
1008 );
1009 0 } catch {
1010 0 $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n"));
1011 0 return Future->fail($@ => json => $resp);
1012 }
1013 })->else(sub {
1014 0 ▶ my ($err, $src, $resp, $req) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
1015 0 $log->warnf("Github failed with error %s on source %s", $err, $src);
1016 0 ▶ $src //= '';
Condition0%0/2
$src //= ""
l!l
00
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
Aresult
11
00
1017 0 ▶ if($src eq 'http') {
Branch: 1 branch
BranchTrueFalseTotal
if ($src eq 'http') { } 0 0 0
1018 0 $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n"));
1019 } else {
1020 0 ▶ $log->errorf("Other failure (%s): %s", $src // 'unknown', $err);
Condition0%0/2
$src // "unknown"
l!l
00
MC/DC0%0/1
$src // "unknown"
$src
Truth table0%0/2
A
A= $src
Aresult
11
00
1021 }
1022 0 Future->fail(@_);
1023 })
1024 0 }
1025  
1026 sub http_delete {
1027 0 ▶ my ($self, %args) = @_;
Subroutine http_delete: not called CC=6 SCAR=37.4
Pod undocumented
1028 0 my %auth = $self->auth_info;
1029  
1030 0 ▶ if(my $hdr = delete $auth{headers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hdr = delete $auth{"headers"}) 0 0 0
1031 0 ▶ $args{headers}{$_} //= $hdr->{$_} for keys %$hdr
Condition0%0/3
$args{"headers"}{$_} //= $hdr->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"headers"}{$_} //= $hdr->{$_}
$args{"headers"}{$_} $hdr->{$_}
Truth table0%0/3
A //= B
A= $args{"headers"}{$_}B= $hdr->{$_}
ABresult
1X1
011
000
1032 }
1033 0 ▶ $args{$_} //= $auth{$_} for keys %auth;
Condition0%0/3
$args{$_} //= $auth{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{$_} //= $auth{$_}
$args{$_} $auth{$_}
Truth table0%0/3
A //= B
A= $args{$_}B= $auth{$_}
ABresult
1X1
011
000
1034  
1035 0 my $uri = delete $args{uri};
1036 0 $log->tracef("DELETE %s { %s }", $uri->as_string, \%args);
1037  
1038 # we never cache deletes
1039 $self->http->do_request(
1040 method => 'DELETE',
1041 uri => $uri,
1042 %args,
1043 )->then(sub {
1044 0 ▶ my ($resp) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
1045 0 $log->tracef("Github response: %s", $resp->as_string("\n"));
1046 # If we had ratelimiting headers, apply them
1047 0 for my $k (qw(Reset Limit Remaining)) {
1048 0 ▶ if(defined(my $v = $resp->header('X-RateLimit-' . $k))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $resp->header('X-RateLimit-' . $k))) 0 0 0
1049 0 my $method = lc $k;
1050 0 $self->core_rate_limit->$method->set_numeric($v);
1051 }
1052 }
1053  
1054 0 ▶ return Future->done(
Branch: 1 branch
BranchTrueFalseTotal
if $resp->code == 204 0 0 0
1055 { },
1056 $resp
1057 ) if $resp->code == 204;
1058 0 ▶ return Future->done(
Branch: 1 branch
BranchTrueFalseTotal
if 3 == $resp->code / 100 0 0 0
1059 { },
1060 $resp
1061 ) if 3 == ($resp->code / 100);
1062 try {
1063 0 return Future->done(
1064 $json->decode(
1065 $resp->decoded_content
1066 ),
1067 $resp
1068 );
1069 0 } catch {
1070 0 $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n"));
1071 0 return Future->fail($@ => json => $resp);
1072 }
1073 })->else(sub {
1074 0 ▶ my ($err, $src, $resp, $req) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
1075 0 $log->warnf("Github failed with error %s on source %s", $err, $src);
1076 0 ▶ $src //= '';
Condition0%0/2
$src //= ""
l!l
00
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
Aresult
11
00
1077 0 ▶ if($src eq 'http') {
Branch: 1 branch
BranchTrueFalseTotal
if ($src eq 'http') { } 0 0 0
1078 0 $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n"));
1079 } else {
1080 0 ▶ $log->errorf("Other failure (%s): %s", $src // 'unknown', $err);
Condition0%0/2
$src // "unknown"
l!l
00
MC/DC0%0/1
$src // "unknown"
$src
Truth table0%0/2
A
A= $src
Aresult
11
00
1081 }
1082 0 Future->fail(@_);
1083 })
1084 0 }
1085  
1086 sub http_put {
1087 0 ▶ my ($self, %args) = @_;
Subroutine http_put: not called CC=8 SCAR=42.8
Pod undocumented
1088 0 my %auth = $self->auth_info;
1089 0 ▶ my $method = delete $args{method} || 'PUT';
Condition0%0/2
delete $args{'method'} || 'PUT'
l!l
00
MC/DC0%0/1
delete $args{'method'} || 'PUT'
delete $args{'method'}
Truth table0%0/2
A
A= delete $args{'method'}
Aresult
11
00
1090  
1091 0 ▶ if(my $hdr = delete $auth{headers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hdr = delete $auth{"headers"}) 0 0 0
1092 0 ▶ $args{headers}{$_} //= $hdr->{$_} for keys %$hdr
Condition0%0/3
$args{"headers"}{$_} //= $hdr->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"headers"}{$_} //= $hdr->{$_}
$args{"headers"}{$_} $hdr->{$_}
Truth table0%0/3
A //= B
A= $args{"headers"}{$_}B= $hdr->{$_}
ABresult
1X1
011
000
1093 }
1094 0 ▶ $args{$_} //= $auth{$_} for keys %auth;
Condition0%0/3
$args{$_} //= $auth{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{$_} //= $auth{$_}
$args{$_} $auth{$_}
Truth table0%0/3
A //= B
A= $args{$_}B= $auth{$_}
ABresult
1X1
011
000
1095  
1096 0 my $uri = delete $args{uri};
1097 0 my $data = delete $args{data};
1098 0 $log->tracef("%s %s { %s } <= %s", $method, $uri->as_string, \%args, $data);
1099 0 ▶ $data = $json->encode($data) if ref $data;
Branch: 1 branch
BranchTrueFalseTotal
if ref $data 0 0 0
1100 $self->http->do_request(
1101 method => $method,
1102 uri => $uri,
1103 content => $data,
1104 content_type => 'application/json',
1105 %args,
1106 )->then(sub {
1107 0 ▶ my ($resp) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
1108 0 $log->tracef("Github response: %s", $resp->as_string("\n"));
1109 # If we had ratelimiting headers, apply them
1110 0 for my $k (qw(Limit Remaining Reset)) {
1111 0 ▶ if(defined(my $v = $resp->header('X-RateLimit-' . $k))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $resp->header('X-RateLimit-' . $k))) 0 0 0
1112 0 my $method = lc $k;
1113 0 $self->core_rate_limit->$method->set_numeric($v);
1114 }
1115 }
1116  
1117 0 ▶ return Future->done(
Branch: 1 branch
BranchTrueFalseTotal
if $resp->code == 204 0 0 0
1118 { },
1119 $resp
1120 ) if $resp->code == 204;
1121 0 ▶ return Future->done(
Branch: 1 branch
BranchTrueFalseTotal
if 3 == $resp->code / 100 0 0 0
1122 { },
1123 $resp
1124 ) if 3 == ($resp->code / 100);
1125 try {
1126 0 return Future->done(
1127 $json->decode(
1128 $resp->decoded_content
1129 ),
1130 $resp
1131 );
1132 0 } catch {
1133 0 $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n"));
1134 0 return Future->fail($@ => json => $resp);
1135 }
1136 })->else(sub {
1137 0 ▶ my ($err, $src, $resp, $req) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
1138 0 $log->warnf("Github failed with error %s on source %s", $err, $src);
1139 0 ▶ $src //= '';
Condition0%0/2
$src //= ""
l!l
00
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
Aresult
11
00
1140 0 ▶ if($src eq 'http') {
Branch: 1 branch
BranchTrueFalseTotal
if ($src eq 'http') { } 0 0 0
1141 0 $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n"));
1142 } else {
1143 0 ▶ $log->errorf("Other failure (%s): %s", $src // 'unknown', $err);
Condition0%0/2
$src // "unknown"
l!l
00
MC/DC0%0/1
$src // "unknown"
$src
Truth table0%0/2
A
A= $src
Aresult
11
00
1144 }
1145 0 Future->fail(@_);
1146 })
1147 0 }
1148  
1149 sub http_patch {
1150 0 ▶ my ($self, %args) = @_;
Subroutine http_patch: not called CC=1 SCAR=6.9
Pod undocumented
1151 0 return $self->http_put(%args, method => 'PATCH');
1152 }
1153  
1154 sub http_post {
1155 0 ▶ my ($self, %args) = @_;
Subroutine http_post: not called CC=7 SCAR=40.3
Pod undocumented
1156 0 my %auth = $self->auth_info;
1157  
1158 0 ▶ if(my $hdr = delete $auth{headers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hdr = delete $auth{"headers"}) 0 0 0
1159 0 ▶ $args{headers}{$_} //= $hdr->{$_} for keys %$hdr
Condition0%0/3
$args{"headers"}{$_} //= $hdr->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"headers"}{$_} //= $hdr->{$_}
$args{"headers"}{$_} $hdr->{$_}
Truth table0%0/3
A //= B
A= $args{"headers"}{$_}B= $hdr->{$_}
ABresult
1X1
011
000
1160 }
1161 0 ▶ $args{$_} //= $auth{$_} for keys %auth;
Condition0%0/3
$args{$_} //= $auth{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{$_} //= $auth{$_}
$args{$_} $auth{$_}
Truth table0%0/3
A //= B
A= $args{$_}B= $auth{$_}
ABresult
1X1
011
000
1162  
1163 0 my $uri = delete $args{uri};
1164 0 my $data = delete $args{data};
1165 0 $log->tracef("POST %s { %s } <= %s", $uri->as_string, \%args, $data);
1166 0 ▶ $data = $json->encode($data) if ref $data;
Branch: 1 branch
BranchTrueFalseTotal
if ref $data 0 0 0
1167 $self->http->POST(
1168 $uri,
1169 $data,
1170 content_type => 'application/json',
1171 %args,
1172 )->then(sub {
1173 0 ▶ my ($resp) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
1174 0 $log->tracef("Github response: %s", $resp->as_string("\n"));
1175 # If we had ratelimiting headers, apply them
1176 0 for my $k (qw(Limit Remaining Reset)) {
1177 0 ▶ if(defined(my $v = $resp->header('X-RateLimit-' . $k))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $resp->header('X-RateLimit-' . $k))) 0 0 0
1178 0 my $method = lc $k;
1179 0 $self->core_rate_limit->$method->set_numeric($v);
1180 }
1181 }
1182  
1183 0 ▶ return Future->done(
Branch: 1 branch
BranchTrueFalseTotal
if $resp->code == 204 0 0 0
1184 { },
1185 $resp
1186 ) if $resp->code == 204;
1187 0 ▶ return Future->done(
Branch: 1 branch
BranchTrueFalseTotal
if 3 == $resp->code / 100 0 0 0
1188 { },
1189 $resp
1190 ) if 3 == ($resp->code / 100);
1191 try {
1192 0 return Future->done(
1193 $json->decode(
1194 $resp->decoded_content
1195 ),
1196 $resp
1197 );
1198 0 } catch {
1199 0 $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n"));
1200 0 return Future->fail($@ => json => $resp);
1201 }
1202 })->else(sub {
1203 0 ▶ my ($err, $src, $resp, $req) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
1204 0 $log->warnf("Github failed with error %s on source %s", $err, $src);
1205 0 ▶ $src //= '';
Condition0%0/2
$src //= ""
l!l
00
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
Aresult
11
00
1206 0 ▶ if($src eq 'http') {
Branch: 1 branch
BranchTrueFalseTotal
if ($src eq 'http') { } 0 0 0
1207 0 $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n"));
1208 } else {
1209 0 ▶ $log->errorf("Other failure (%s): %s", $src // 'unknown', $err);
Condition0%0/2
$src // "unknown"
l!l
00
MC/DC0%0/1
$src // "unknown"
$src
Truth table0%0/2
A
A= $src
Aresult
11
00
1210 }
1211 0 Future->fail(@_);
1212 })
1213 0 }
1214  
1215 sub api_get_list {
1216 1 ▶ use Variable::Disposition qw(retain_future);
Subroutine BEGIN: called CC=1 SCAR=0.0
1217 1 ▶ use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
1218 1 ▶ use Future::Utils qw(fmap0);
Subroutine BEGIN: called CC=1 SCAR=0.0
1219 1 ▶ use namespace::clean qw(retain_future fmap0 refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
1220  
1221 0 ▶ my ($self, %args) = @_;
Subroutine api_get_list: not called CC=6 SCAR=37.4
Pod undocumented
1222 my $label = $args{endpoint}
1223 0 ▶ ? ('Github[' . $args{endpoint} . ']')
Branch: 1 branch
BranchTrueFalseTotal
$args{'endpoint'} ? : 0 0 0
1224 : (caller 1)[3];
1225  
1226 0 ▶ die "Must be a member of a ::Loop" unless $self->loop;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->loop 0 0 0
1227  
1228 # Hoist our HTTP API call into a source of items
1229 0 my $src = $self->ryu->source(
1230 label => $label
1231 );
1232 my $uri = $args{endpoint}
1233 ? $self->endpoint(
1234 $args{endpoint},
1235 0 ▶ %{$args{endpoint_args}}
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'uri'} ? : 0 0 0
1236 ) : ref $args{uri}
1237 ? $args{uri}
1238 : URI->new(
1239 $self->base_uri . delete($args{uri})
1240 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$args{'endpoint'} ? : 0 0 0
1241  
1242 0 ▶ my $per_page = (delete $args{per_page}) || 100;
Condition0%0/2
delete $args{'per_page'} || 100
l!l
00
MC/DC0%0/1
delete $args{'per_page'} || 100
delete $args{'per_page'}
Truth table0%0/2
A
A= delete $args{'per_page'}
Aresult
11
00
1243 0 $uri->query_param(
1244 limit => $per_page
1245 );
1246 0 my @pending = $uri;
1247 my $f = (fmap0 {
1248 0 ▶ my $uri = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1249 $self->http_get(
1250 uri => $uri,
1251 )->on_done(sub {
1252 0 ▶ my ($data, $resp) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
1253 # Handle paging - this takes the form of zero or more Link headers like this:
1254 # Link: <https://api.github.com/user/repos?page=2>; rel="next"
1255 0 for my $link (map { split /\s*,\s*/, $_ } $resp->header('Link')) {
1256 0 ▶ if($link =~ m{<([^>]+)>; rel="next"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link =~ /<([^>]+)>; rel="next"/) 0 0 0
1257 0 push @pending, URI->new($1);
1258 }
1259 }
1260  
1261 $src->emit(
1262 $args{class}->new(
1263 %$_,
1264 0 ($args{extra} ? %{$args{extra}} : ()),
1265 github => $self
1266 )
1267 0 ▶ ) for @{ $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
$args{'extra'} ? : 0 0 0
1268 })->on_fail(sub {
1269 0 ▶ warn "fail - @_";
Subroutine __ANON__: not called CC=1 SCAR=6.9
1270 0 $src->fail(@_)
1271 })->on_cancel(sub {
1272 0 ▶ warn "cancel - @_";
Subroutine __ANON__: not called CC=1 SCAR=6.9
1273 0 $src->cancel
1274 0 });
1275 } foreach => \@pending)->on_done(sub {
1276 0 ▶ $src->finish;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1277 0 });
1278  
1279 # If our source finishes earlier than our HTTP request, then cancel the request
1280 $src->completed->on_ready(sub {
1281 0 ▶ return if $f->is_ready;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_ready 0 0 0
1282 0 $log->tracef("Finishing HTTP request early for %s since our source is no longer active", $label);
1283 0 $f->cancel
1284 0 });
1285  
1286 # Track active requests
1287 0 my $refaddr = Scalar::Util::refaddr($f);
1288 $self->pending_requests->push([ {
1289 id => $refaddr,
1290 src => $src,
1291 uri => $uri,
1292 future => $f,
1293 } ])->then(sub {
1294 $f->on_ready(sub {
1295 retain_future(
1296 0 ▶ $self->pending_requests->extract_first_by(sub { $_->{id} == $refaddr })
Subroutine __ANON__: not called CC=1 SCAR=6.9
1297 0 ▶ )
Subroutine __ANON__: not called CC=1 SCAR=6.9
1298 0 ▶ });
Subroutine __ANON__: not called CC=1 SCAR=6.9
1299 0 })->retain;
1300 0 $src
1301 }
1302  
1303 =head2 pending_requests
1304  
1305 A list of all pending requests.
1306  
1307 =cut
1308  
1309 sub pending_requests {
1310 0 ▶ shift->{pending_requests} //= do {
Subroutine pending_requests: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
+(shift())->{"pending_requests"} //= do { require Adapter::Async::OrderedList::Array; "Adapter::Async::OrderedList::Array"->new }
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->{"pending_requests"} //= do { require Adapter::Async::OrderedList::Array; "Adapter::Async::OrderedList::Array"->new }
+(shift())->{"pending_requests"} do { require Adapter::Async::OrderedList::Array; "Adapter::Async::OrderedList::Array"->new }
Truth table0%0/3
A //= B
A= +(shift())->{"pending_requests"}B= do { require Adapter::Async::OrderedList::Array; "Adapter::Async::OrderedList::Array"->new }
ABresult
1X1
011
000
1311 0 require Adapter::Async::OrderedList::Array;
1312 0 Adapter::Async::OrderedList::Array->new
1313 }
1314 }
1315  
1316 =head2 validate_branch_name
1317  
1318 Applies validation rules from L<git-check-ref-format> for a branch name.
1319  
1320 Will raise an exception on invalid input.
1321  
1322 =cut
1323  
1324 sub validate_branch_name {
1325 0 ▶ my ($self, $branch) = @_;
Subroutine validate_branch_name: not called CC=7 SCAR=40.3
Pod documented
1326 0 ▶ die "branch not defined" unless defined $branch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $branch 0 0 0
1327 0 ▶ die "branch contains path component with leading ." if $branch =~ m{/\.};
Branch: 1 branch
BranchTrueFalseTotal
if $branch =~ m[/\.] 0 0 0
1328 0 ▶ die "branch contains double ." if $branch =~ m{\.\.};
Branch: 1 branch
BranchTrueFalseTotal
if $branch =~ /\.\./ 0 0 0
1329 0 ▶ die "branch contains invalid character(s)" if $branch =~ m{[[:cntrl:][:space:]~^:\\]};
Branch: 1 branch
BranchTrueFalseTotal
if $branch =~ /[[:cntrl:][:space:]~^:\\]/ 0 0 0
1330 0 ▶ die "branch ends with /" if substr($branch, -1) eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if substr($branch, -1) eq "/" 0 0 0
1331 0 ▶ die "branch ends with .lock" if substr($branch, -5) eq '.lock';
Branch: 1 branch
BranchTrueFalseTotal
if substr($branch, -5) eq ".lock" 0 0 0
1332 0 return 1;
1333 }
1334  
1335 =head2 validate_owner_name
1336  
1337 Applies github rules for user/organisation name.
1338  
1339 Will raise an exception on invalid input.
1340  
1341 =cut
1342  
1343 sub validate_owner_name {
1344 0 ▶ my ($self, $owner) = @_;
Subroutine validate_owner_name: not called CC=7 SCAR=40.3
Pod documented
1345 0 ▶ die "owner name not defined" unless defined $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $owner 0 0 0
1346 0 ▶ die "owner name too long" if length($owner) > 39;
Branch: 1 branch
BranchTrueFalseTotal
if length $owner > 39 0 0 0
1347 0 ▶ die "owner name contains invalid characters" if $owner =~ /[^a-z0-9-]/i;
Branch: 1 branch
BranchTrueFalseTotal
if $owner =~ /[^a-z0-9-]/i 0 0 0
1348 0 ▶ die "owner name contains double hyphens" if $owner =~ /--/;
Branch: 1 branch
BranchTrueFalseTotal
if $owner =~ /--/ 0 0 0
1349 0 ▶ die "owner name contains leading hyphen" if $owner =~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
if $owner =~ /^-/ 0 0 0
1350 0 ▶ die "owner name contains trailing hyphen" if $owner =~ /-$/;
Branch: 1 branch
BranchTrueFalseTotal
if $owner =~ /-$/ 0 0 0
1351 0 return 1;
1352 }
1353  
1354 =head2 validate_repo_name
1355  
1356 Applies github rules for repository name.
1357  
1358 Will raise an exception on invalid input.
1359  
1360 =cut
1361  
1362 sub validate_repo_name {
1363 0 ▶ my ($self, $repo) = @_;
Subroutine validate_repo_name: not called CC=4 SCAR=30.0
Pod documented
1364 0 ▶ die "repo name not defined" unless defined $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo 0 0 0
1365 # Not really as well-defined as I'd like, closest to an official answer seems to be here:
1366 # https://github.community/t/github-repository-name-vs-description-vs-readme-heading-h1/3284
1367 # There are repositories with underscores, but that seems to be strongly discouraged:
1368 # https://github.com/Automattic/_s
1369 # Canonical repositories with '. character would include the `.wiki` "magic" repo for each
1370 # Github repo
1371 0 ▶ die "repo name contains invalid characters" if $repo =~ /[^a-z0-9.-]/i;
Branch: 1 branch
BranchTrueFalseTotal
if $repo =~ /[^a-z0-9.-]/i 0 0 0
1372 0 ▶ die "repo name too long" if length($repo) > 100;
Branch: 1 branch
BranchTrueFalseTotal
if length $repo > 100 0 0 0
1373 0 return 1;
1374 }
1375  
1376 =head2 validate_args
1377  
1378 Convenience method to apply validation on common parameters.
1379  
1380 =cut
1381  
1382 sub validate_args {
1383 0 ▶ my ($self, %args) = @_;
Subroutine validate_args: not called CC=4 SCAR=30.0
Pod documented
1384 0 ▶ $self->validate_branch_name($args{branch}) if exists $args{branch};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"branch"} 0 0 0
1385 0 ▶ $self->validate_owner_name($args{owner}) if exists $args{owner};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"owner"} 0 0 0
1386 0 ▶ $self->validate_repo_name($args{repo}) if exists $args{repo};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"repo"} 0 0 0
1387 }
1388  
1389 =head2 page_cache_size
1390  
1391 Returns the total number of GET responses we'll cache. Default is probably 1000.
1392  
1393 =cut
1394  
1395 0 ▶sub page_cache_size { shift->{page_cache_size} //= 1000 }
Subroutine page_cache_size: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
+(shift())->{"page_cache_size"} //= 1000
l!l
00
MC/DC0%0/1
+(shift())->{"page_cache_size"} //= 1000
+(shift())->{"page_cache_size"}
Truth table0%0/2
A
A= +(shift())->{"page_cache_size"}
Aresult
11
00
1396  
1397 =head2 page_cache
1398  
1399 The page cache instance, likely to be provided by L<Cache::LRU>.
1400 =cut
1401  
1402 sub page_cache {
1403 0 ▶ $_[0]->{page_cache} //= do {
Subroutine page_cache: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$_[0]{"page_cache"} //= do { "Cache::LRU"->new("size", $_[0]->page_cache_size) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"page_cache"} //= do { "Cache::LRU"->new("size", $_[0]->page_cache_size) }
$_[0]{"page_cache"} do { "Cache::LRU"->new("size", $_[0]->page_cache_size) }
Truth table0%0/3
A //= B
A= $_[0]{"page_cache"}B= do { "Cache::LRU"->new("size", $_[0]->page_cache_size) }
ABresult
1X1
011
000
1404 0 Cache::LRU->new(
1405 size => $_[0]->page_cache_size
1406 )
1407 }
1408 }
1409  
1410 =head2 ryu
1411  
1412 Our L<Ryu::Async> instance, used for instantiating L<Ryu::Source> instances.
1413  
1414 =cut
1415  
1416 0 ▶sub ryu { shift->{ryu} }
Subroutine ryu: not called CC=1 SCAR=6.9
Pod documented
1417  
1418 sub _add_to_loop {
1419 0 ▶ my ($self, $loop) = @_;
Subroutine _add_to_loop: not called CC=1 SCAR=6.9
1420  
1421 # Hand out sources and sinks
1422 $self->add_child(
1423 0 $self->{ryu} = Ryu::Async->new
1424 );
1425  
1426 }
1427  
1428 sub ws {
1429 0 ▶ my ($self) = @_;
Subroutine ws: not called CC=2 SCAR=17.9
Pod undocumented
1430 0 ▶ $self->{ws} // do {
Condition0%0/3
$self->{"ws"} // do { require Net::Async::WebSocket::Client; $self->add_child(my $ws = "Net::Async::WebSocket::Client"->new("on_frame", $self->curry::weak::on_frame)); builtin::weaken($self->{"ws"} = $ws); $ws }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ws"} // do { require Net::Async::WebSocket::Client; $self->add_child(my $ws = "Net::Async::WebSocket::Client"->new("on_frame", $self->curry::weak::on_frame)); builtin::weaken($self->{"ws"} = $ws); $ws }
$self->{"ws"} do { require Net::Async::WebSocket::Client; $self->add_child(my $ws = "Net::Async::WebSocket::Client"->new("on_frame", $self->curry::weak::on_frame)); builtin::weaken($self->{"ws"} = $ws); $ws }
Truth table0%0/3
A // B
A= $self->{"ws"}B= do { require Net::Async::WebSocket::Client; $self->add_child(my $ws = "Net::Async::WebSocket::Client"->new("on_frame", $self->curry::weak::on_frame)); builtin::weaken($self->{"ws"} = $ws); $ws }
ABresult
1X1
011
000
1431 0 require Net::Async::WebSocket::Client;
1432 0 $self->add_child(
1433 my $ws = Net::Async::WebSocket::Client->new(
1434 on_frame => $self->curry::weak::on_frame,
1435 )
1436 );
1437 0 Scalar::Util::weaken($self->{ws} = $ws);
1438 0 $ws
1439 };
1440 }
1441  
1442 1 1;
1443  
1444 =head1 AUTHOR
1445  
1446 Tom Molesworth <TEAM@cpan.org>, with contributions from C<< @chylli-binary >>.
1447  
1448 =head1 LICENSE
1449  
1450 Copyright Tom Molesworth 2014-2021. Licensed under the same terms as Perl itself.
1451  
↑ Summary Github/Repository.pm »