line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GitHub::MergeVelocity::Repository; |
2
|
|
|
|
|
|
|
$GitHub::MergeVelocity::Repository::VERSION = '0.000007'; |
3
|
2
|
|
|
2
|
|
89149
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
835
|
use GitHub::MergeVelocity::Repository::PullRequest; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
87
|
|
7
|
2
|
|
|
2
|
|
1231
|
use GitHub::MergeVelocity::Repository::Statistics; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
83
|
|
8
|
2
|
|
|
2
|
|
14
|
use Moo; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
9
|
2
|
|
|
2
|
|
614
|
use MooX::StrictConstructor; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
15
|
|
10
|
2
|
|
|
2
|
|
1293
|
use Types::Standard qw( ArrayRef Bool InstanceOf Str ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
24
|
|
11
|
2
|
|
|
2
|
|
3212
|
use URI (); |
|
2
|
|
|
|
|
8725
|
|
|
2
|
|
|
|
|
1214
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $self = shift; |
26
|
|
|
|
|
|
|
my ( undef, $name ) = $self->_parse_github_url( $self->url ); |
27
|
|
|
|
|
|
|
return $name; |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
my ($user) = $self->_parse_github_url( $self->url ); |
53
|
|
|
|
|
|
|
return $user; |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _build_report { |
58
|
1
|
|
|
1
|
|
540
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
4
|
my $pulls = $self->_get_pull_requests; |
61
|
|
|
|
|
|
|
|
62
|
1
|
50
|
|
|
|
6
|
my $total = $pulls ? scalar @{$pulls} : 0; |
|
1
|
|
|
|
|
2
|
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
5
|
my %summary = ( total_velocity => 0 ); |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
1
|
foreach my $pr ( @{$pulls} ) { |
|
1
|
|
|
|
|
3
|
|
67
|
13
|
|
|
|
|
389
|
$summary{ $pr->state }++; |
68
|
13
|
|
|
|
|
387
|
$summary{ $pr->state . '_age' } += $pr->age; |
69
|
13
|
|
|
|
|
1408
|
$summary{total_velocity} += $pr->velocity; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
28
|
return GitHub::MergeVelocity::Repository::Statistics->new(%summary); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
## no critic (ValuesAndExpressions::ProhibitAccessOfPrivateData) |
76
|
|
|
|
|
|
|
sub _get_pull_requests { |
77
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
6
|
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
|
|
|
|
|
1051023
|
my @pulls; |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
6
|
while ( my $row = $result->next ) { |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# GunioRobot seems to create pull requests that clean up whitespace |
90
|
13
|
50
|
33
|
|
|
5185
|
next if !$row->{user} || $row->{user}->{login} eq 'GunioRobot'; |
91
|
|
|
|
|
|
|
|
92
|
13
|
50
|
|
|
|
313
|
my $pull_request |
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
13
|
|
|
|
|
4034
|
push @pulls, $pull_request; |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
578
|
return \@pulls; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
## use critic |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _parse_github_url { |
108
|
12
|
|
|
12
|
|
20
|
my $self = shift; |
109
|
12
|
|
|
|
|
49
|
my $uri = URI->new(shift); |
110
|
|
|
|
|
|
|
|
111
|
12
|
|
|
|
|
760
|
my @parts = split m{/}, $uri->path; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# paths may or may not have a leading slash (absolute vs relative) |
114
|
12
|
|
66
|
|
|
601
|
my $user = shift @parts || shift @parts; |
115
|
12
|
|
|
|
|
16
|
my $name = shift @parts; |
116
|
12
|
|
|
|
|
33
|
$name =~ s{\.git}{}; |
117
|
|
|
|
|
|
|
|
118
|
12
|
|
|
|
|
62
|
return ( $user, $name ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|