Github.pm

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