blib/lib/GitHub/MergeVelocity/Repository.pm

filter: Statementstmt 100% 63 / 63 Branchbran 80.0% 8 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 90.6% 87 / 96 CC 9 SCAR 10.5
CC
9
Cov
94%
_get_pull_requests
6.1
_build_report
3.0
_parse_github_url
2.0
CRAP 2.9
« blib/lib/GitHub/MergeVelocity/Repository/PullRequest.pm ↑ Summary blib/lib/GitHub/MergeVelocity/Repository/Statistics.pm »
1 package GitHub::MergeVelocity::Repository;
2 2 $GitHub::MergeVelocity::Repository::VERSION = '0.000007';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use GitHub::MergeVelocity::Repository::PullRequest;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use GitHub::MergeVelocity::Repository::Statistics;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MooX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Types::Standard qw( ArrayRef Bool InstanceOf Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 has github_client => (
14 is => 'ro',
15 isa => InstanceOf ['Pithub::PullRequests'],
16 required => 1,
17 );
18  
19 has name => (
20 is => 'ro',
21 isa => Str,
22 init_arg => undef,
23 lazy => 1,
24 default => sub {
25 6 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
26 6 my ( undef, $name ) = $self->_parse_github_url( $self->url );
27 6 return $name;
28 },
29 2 );
30  
31 2 has report => (
32 is => 'ro',
33 isa => InstanceOf ['GitHub::MergeVelocity::Repository::Statistics'],
34 init_arg => undef,
35 lazy => 1,
36 builder => '_build_report',
37 );
38  
39 2 has url => (
40 is => 'ro',
41 isa => Str,
42 required => 1,
43 );
44  
45 has user => (
46 is => 'ro',
47 isa => Str,
48 init_arg => undef,
49 lazy => 1,
50 default => sub {
51 6 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
52 6 my ($user) = $self->_parse_github_url( $self->url );
53 6 return $user;
54 },
55 2 );
56  
57 sub _build_report {
58 1 ▶ my $self = shift;
Subroutine _build_report: called CC=3 SCAR=11.0
59  
60 1 my $pulls = $self->_get_pull_requests;
61  
62 1 ▶ my $total = $pulls ? scalar @{$pulls} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$pulls ? : 1 0 1
63  
64 1 my %summary = ( total_velocity => 0 );
65  
66 1 foreach my $pr ( @{$pulls} ) {
67 40 $summary{ $pr->state }++;
68 40 $summary{ $pr->state . '_age' } += $pr->age;
69 40 $summary{total_velocity} += $pr->velocity;
70 }
71  
72 1 return GitHub::MergeVelocity::Repository::Statistics->new(%summary);
73 }
74  
75 ## no critic (ValuesAndExpressions::ProhibitAccessOfPrivateData)
76 sub _get_pull_requests {
77 1 ▶ my $self = shift;
Subroutine _get_pull_requests: called CC=6 SCAR=18.2
78  
79 1 my $result = $self->github_client->list(
80 user => $self->user,
81 repo => $self->name,
82 params => { per_page => 100, state => 'all' },
83 );
84  
85 1 my @pulls;
86  
87 1 ▶ while ( my $row = $result->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $result->next) 40 1 41
88  
89 # GunioRobot seems to create pull requests that clean up whitespace
90 40 ▶ next if !$row->{user} || $row->{user}->{login} eq 'GunioRobot';
Branch: 1 branch
BranchTrueFalseTotal
if not $row->{"user"} or $row->{"user"}{"login"} eq "GunioRobot" 0 40 40
Condition33%1/3
not $row->{"user"} or $row->{"user"}{"login"} eq "GunioRobot"
l!l&&r!l&&!r
0040
MC/DC0%0/2
not $row->{"user"} or $row->{"user"}{"login"} eq "GunioRobot"
not $row->{"user"} $row->{"user"}{"login"} eq "GunioRobot"
Truth table33%1/3
not(A) or B
A= not $row->{"user"}B= $row->{"user"}{"login"} eq "GunioRobot"
ABresult
1X1
011
000
91  
92 my $pull_request
93 = GitHub::MergeVelocity::Repository::PullRequest->new(
94 created_at => $row->{created_at},
95 $row->{closed_at} ? ( closed_at => $row->{closed_at} ) : (),
96 $row->{merged_at} ? ( merged_at => $row->{merged_at} ) : (),
97 number => $row->{number},
98 title => $row->{title},
99 40 ▶ );
Branch: 2 branches
BranchTrueFalseTotal
$row->{'closed_at'} ? : 37 3 40
$row->{'merged_at'} ? : 28 12 40
100  
101 40 push @pulls, $pull_request;
102 }
103 1 return \@pulls;
104 }
105 ## use critic
106  
107 sub _parse_github_url {
108 12 ▶ my $self = shift;
Subroutine _parse_github_url: called CC=2 SCAR=7.0
109 12 my $uri = URI->new(shift);
110  
111 12 my @parts = split m{/}, $uri->path;
112  
113 # paths may or may not have a leading slash (absolute vs relative)
114 12 ▶ my $user = shift @parts || shift @parts;
Condition66%2/3
shift @parts || shift @parts
l!l&&r!l&&!r
480
MC/DC0%0/2
shift @parts || shift @parts
shift @parts shift @parts
Truth table66%2/3
A || B
A= shift @partsB= shift @parts
ABresult
1X1
011
000
115 12 my $name = shift @parts;
116 12 $name =~ s{\.git}{};
117  
118 12 return ( $user, $name );
119 }
120  
121 2 1;
122  
123 =pod
124  
125 =encoding UTF-8
126  
127 =head1 NAME
128  
129 GitHub::MergeVelocity::Repository - Encapsulate pull request data for a repository
130  
131 =head1 VERSION
132  
133 version 0.000007
134  
135 =head1 AUTHOR
136  
137 Olaf Alders <olaf@wundercounter.com>
138  
139 =head1 COPYRIGHT AND LICENSE
140  
141 This software is copyright (c) 2015 by Olaf Alders.
142  
143 This is free software; you can redistribute it and/or modify it under
144 the same terms as the Perl 5 programming language system itself.
145  
146 =cut
147  
148 __END__
149  
150 # ABSTRACT: Encapsulate pull request data for a repository
151  
« blib/lib/GitHub/MergeVelocity/Repository/PullRequest.pm ↑ Summary blib/lib/GitHub/MergeVelocity/Repository/Statistics.pm »