line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GitHub::MergeVelocity::Repository; |
2
|
|
|
|
|
|
|
$GitHub::MergeVelocity::Repository::VERSION = '0.000006'; |
3
|
2
|
|
|
2
|
|
61533
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
51
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
671
|
use GitHub::MergeVelocity::Repository::PullRequest; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
103
|
|
7
|
2
|
|
|
2
|
|
1144
|
use GitHub::MergeVelocity::Repository::Statistics; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
71
|
|
8
|
2
|
|
|
2
|
|
23
|
use Moo; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
9
|
2
|
|
|
2
|
|
496
|
use MooX::StrictConstructor; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
15
|
|
10
|
2
|
|
|
2
|
|
1157
|
use Types::Standard qw( ArrayRef Bool InstanceOf Str ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
23
|
|
11
|
2
|
|
|
2
|
|
2862
|
use URI (); |
|
2
|
|
|
|
|
6973
|
|
|
2
|
|
|
|
|
902
|
|
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
|
|
518
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
5
|
my $pulls = $self->_get_pull_requests; |
61
|
|
|
|
|
|
|
|
62
|
1
|
50
|
|
|
|
6
|
my $total = $pulls ? scalar @{$pulls} : 0; |
|
1
|
|
|
|
|
3
|
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
3
|
my %summary = ( total_velocity => 0 ); |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
2
|
foreach my $pr ( @{$pulls} ) { |
|
1
|
|
|
|
|
3
|
|
67
|
13
|
|
|
|
|
373
|
$summary{ $pr->state }++; |
68
|
13
|
|
|
|
|
408
|
$summary{ $pr->state . '_age' } += $pr->age; |
69
|
13
|
|
|
|
|
1430
|
$summary{total_velocity} += $pr->velocity; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
33
|
return GitHub::MergeVelocity::Repository::Statistics->new(%summary); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
## no critic (ValuesAndExpressions::ProhibitAccessOfPrivateData) |
76
|
|
|
|
|
|
|
sub _get_pull_requests { |
77
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
7
|
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
|
|
|
|
|
1120136
|
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
|
|
|
5409
|
next if !$row->{user} || $row->{user}->{login} eq 'GunioRobot'; |
91
|
|
|
|
|
|
|
|
92
|
13
|
50
|
|
|
|
366
|
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
|
|
|
|
|
4574
|
push @pulls, $pull_request; |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
506
|
return \@pulls; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
## use critic |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _parse_github_url { |
108
|
12
|
|
|
12
|
|
18
|
my $self = shift; |
109
|
12
|
|
|
|
|
50
|
my $uri = URI->new(shift); |
110
|
|
|
|
|
|
|
|
111
|
12
|
|
|
|
|
797
|
my @parts = split m{/}, $uri->path; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# paths may or may not have a leading slash (absolute vs relative) |
114
|
12
|
|
66
|
|
|
587
|
my $user = shift @parts || shift @parts; |
115
|
12
|
|
|
|
|
18
|
my $name = shift @parts; |
116
|
12
|
|
|
|
|
34
|
$name =~ s{\.git}{}; |
117
|
|
|
|
|
|
|
|
118
|
12
|
|
|
|
|
60
|
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.000006 |
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
|
|
|
|
|
|
|
|