MergeVelocity.pm

filter: Statementstmt 87.3% 90 / 103 Branchbran 35.7% 5 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 95.6% 22 / 23 Podpod 0.0% 0 / 2 totaltotal 80.2% 118 / 147 CC 11 SCAR 11.9
CC
11
Cov
80%
_build_mech
12.0
_build_github_client
7.3
_columns_for_state
3.1
CRAP 3.3
↑ Summary MergeVelocity/Repository/PullRequest.pm »
1 package GitHub::MergeVelocity;
2 1 our $VERSION = '0.000008';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use CLDR::Number::Format::Percent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::HomeDir ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use GitHub::MergeVelocity::Repository ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Module::Runtime qw( require_module use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Moo 1.007000;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use MooX::HandlesVia;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MooX::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use MooX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Pithub::PullRequests ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Text::SimpleTable::AutoWidth;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Types::Standard qw( ArrayRef Bool HashRef InstanceOf Int Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use WWW::Mechanize::GZip ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 option debug_useragent => (
21 is => 'ro',
22 isa => Int,
23 format => 'i',
24 default => 0,
25 documentation => 'Print a _lot_ of debugging info about LWP requests',
26 );
27  
28 1 my $token_help = <<'EOF';
29 https://help.github.com/articles/creating-an-access-token-for-command-line-use for instructions on how to get your own GitHub access token
30 EOF
31  
32 1 option cache_requests => (
33 is => 'ro',
34 isa => Bool,
35 documentation => 'Try to cache GET requests',
36 );
37  
38 1 option github_token => (
39 is => 'ro',
40 isa => Str,
41 required => 0,
42 format => 's',
43 documentation => $token_help,
44 );
45  
46 1 option github_user => (
47 is => 'ro',
48 isa => Str,
49 required => 0,
50 format => 's',
51 documentation => 'The username of your GitHub account',
52 );
53  
54 1 option url => (
55 is => 'ro',
56 isa => ArrayRef,
57 format => 's@',
58 required => 1,
59 documentation =>
60 'Full Github repo url or shorthand of username/repository. You can pass multiple url args.',
61 );
62  
63 1 has _report => (
64 is => 'ro',
65 isa => HashRef,
66 handles_via => 'Hash',
67 init_arg => undef,
68 handles => { _repository_for_url => 'get', _report_urls => 'keys', },
69 lazy => 1,
70 builder => '_build_report',
71 );
72  
73 1 has _github_client => (
74 is => 'ro',
75 isa => InstanceOf ['Pithub::PullRequests'],
76 lazy => 1,
77 builder => '_build_github_client'
78 );
79  
80 1 has _mech => (
81 is => 'ro',
82 isa => InstanceOf ['LWP::UserAgent'],
83 lazy => 1,
84 builder => '_build_mech',
85 );
86  
87 has _percent_formatter => (
88 is => 'ro',
89 isa => InstanceOf ['CLDR::Number::Format::Percent'],
90 handles => { '_format_percent' => 'format' },
91 lazy => 1,
92 1 ▶ default => sub { CLDR::Number::Format::Percent->new( locale => 'en' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
93 1 );
94  
95 sub _build_github_client {
96 1 ▶ my $self = shift;
Subroutine _build_github_client: called CC=5 SCAR=19.9
97 1 ▶ return Pithub::PullRequests->new(
Branch: 3 branches
BranchTrueFalseTotal
$self->cache_requests || $self->debug_useragent ? : 0 1 1
$self->github_user ? : 0 1 1
$self->github_token ? : 0 1 1
Condition33%1/3
$self->cache_requests or $self->debug_useragent
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->cache_requests or $self->debug_useragent
$self->cache_requests $self->debug_useragent
Truth table33%1/3
A or B
A= $self->cache_requestsB= $self->debug_useragent
ABresult
1X1
011
000
98 $self->cache_requests
99 || $self->debug_useragent ? ( ua => $self->_mech ) : (),
100 $self->github_user ? ( user => $self->github_user ) : (),
101 $self->github_token ? ( token => $self->github_token ) : (),
102 );
103 }
104  
105 sub _build_mech {
106 0 ▶ my $self = shift;
Subroutine _build_mech: not called CC=3 SCAR=24.8
107  
108 0 my $mech;
109  
110 0 ▶ if ( $self->cache_requests ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cache_requests) { } 0 0 0
111 0 my $dir = path( File::HomeDir->my_home );
112 0 $dir->child('.github-mergevelocity-cache')->mkpath;
113  
114 0 require_module('CHI');
115 0 $mech = use_module( 'WWW::Mechanize::Cached', 1.45 )->new(
116 cache => CHI->new(
117 driver => 'File',
118 root_dir => $dir->stringify,
119 )
120 );
121 }
122 else {
123 0 $mech = WWW::Mechanize::GZip->new;
124 }
125 0 ▶ if ( $self->debug_useragent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug_useragent) 0 0 0
126 0 use_module( 'LWP::ConsoleLogger::Easy', 0.000013 );
127 0 LWP::ConsoleLogger::Easy::debug_ua( $mech, $self->debug_useragent );
128 }
129 0 return $mech;
130 }
131  
132 sub _build_report {
133 1 ▶ my $self = shift;
Subroutine _build_report: called CC=2 SCAR=6.9
134  
135 1 my %report;
136  
137 1 foreach my $url ( @{ $self->url } ) {
138 1 my $repo = GitHub::MergeVelocity::Repository->new(
139 github_client => $self->_github_client,
140 url => $url,
141 );
142 1 $report{$url} = $repo;
143 }
144 1 return \%report;
145 }
146  
147 # workaround for init_arg being ignored
148 # https://rt.cpan.org/Ticket/Display.html?id=97849
149  
150 sub report {
151 1 ▶ my $self = shift;
Subroutine report: called CC=1 SCAR=0.0
Pod undocumented
152 1 return $self->_report;
153 }
154  
155 sub print_report {
156 1 ▶ my $self = shift;
Subroutine print_report: called CC=2 SCAR=6.9
Pod undocumented
157  
158 1 my $table = Text::SimpleTable::AutoWidth->new;
159 1 my @cols = (
160 'user', 'repo', 'velocity', 'PRs',
161 'merged', 'merge days', 'closed', 'close days',
162 'open', 'open days',
163 );
164 1 $table->captions( \@cols );
165  
166 1 my @repos = map { $self->_repository_for_url($_) } $self->_report_urls;
167  
168 1 foreach my $repository (
169 0 sort { $b->report->average_velocity <=> $a->report->average_velocity }
170 @repos
171 )
172 {
173 1 my $report = $repository->report;
174 $table->row(
175 $repository->user,
176 $repository->name,
177 $report->average_velocity,
178 $report->pull_request_count,
179 1 map { $self->_columns_for_state( $report, $_ ) }
180 ( 'merged', 'closed', 'open' ),
181 );
182 }
183  
184 1 ▶ binmode( STDOUT, ':encoding(UTF-8)' );
Subroutine BEGIN: called CC=1 SCAR=0.0
185 1 print $table->draw;
186 1 return;
187 }
188  
189 sub _columns_for_state {
190 3 ▶ my $self = shift;
Subroutine _columns_for_state: called CC=3 SCAR=11.3
191 3 my $report = shift;
192 3 my $state = shift;
193 3 my $age = $state . '_age';
194  
195 return (
196 3 ▶ $report->$state
Branch: 2 branches
BranchTrueFalseTotal
$report->$state ? : 3 0 3
$report->$age ? : 3 0 3
197 ? sprintf( '%s (%i)',
198 $self->_format_percent( $report->percentage_in_state($state) ),
199 $report->$state )
200 : 0,
201 $report->$age ? sprintf( '%s/PR (%i)',
202 $report->average_age_for_state($state),
203 $report->$age ) : 0,
204 );
205 }
206  
207 1 1;
208  
209 =pod
210  
211 =encoding UTF-8
212  
213 =head1 NAME
214  
215 GitHub::MergeVelocity - Determine how quickly your pull request might get merged
216  
217 =head1 VERSION
218  
219 version 0.000008
220  
221 =head1 SYNOPSIS
222  
223 use strict;
224 use warnings;
225  
226 use GitHub::MergeVelocity;
227  
228 my $velocity = GitHub::MergeVelocity->new(
229 url => [
230 'https://github.com/neilbowers/PAUSE-Permissions',
231 'https://github.com/oalders/html-restrict',
232 ]
233 );
234  
235 my $report = $velocity->report;
236  
237 $velocity->print_report; # prints a tabular report
238  
239 =head1 CAVEATS
240  
241 This module cannot (yet) distinguish between pull requests which were closed
242 because they were rejected and pull requests which were closed because the
243 patches were applied outside of GitHub's merge mechanism.
244  
245 =head1 AUTHOR
246  
247 Olaf Alders <olaf@wundercounter.com>
248  
249 =head1 COPYRIGHT AND LICENSE
250  
251 This software is copyright (c) 2015 by Olaf Alders.
252  
253 This is free software; you can redistribute it and/or modify it under
254 the same terms as the Perl 5 programming language system itself.
255  
256 =cut
257  
258 __END__
259  
260 # ABSTRACT: Determine how quickly your pull request might get merged
261  
↑ Summary MergeVelocity/Repository/PullRequest.pm »