| 1 | package GitHub::MergeVelocity::Repository::PullRequest; | ||||||||||||||
| 2 | 3 | $GitHub::MergeVelocity::Repository::PullRequest::VERSION = '0.000007'; | |||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 3 | ▶ | use DateTime; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 3 | ▶ | use GitHub::MergeVelocity::Types qw( Datetime ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 3 | ▶ | use Math::Round qw( round ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 3 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 3 | ▶ | use MooX::StrictConstructor; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 3 | ▶ | use Types::Standard qw( Bool Int Str ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 3 | has age => ( | |||||||||||||
| 14 | is => 'ro', | ||||||||||||||
| 15 | init_arg => undef, | ||||||||||||||
| 16 | isa => Int, | ||||||||||||||
| 17 | lazy => 1, | ||||||||||||||
| 18 | builder => '_build_age', | ||||||||||||||
| 19 | ); | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 3 | has closed_at => ( | |||||||||||||
| 22 | is => 'ro', | ||||||||||||||
| 23 | isa => Datetime, | ||||||||||||||
| 24 | predicate => 'is_closed', | ||||||||||||||
| 25 | coerce => 1, | ||||||||||||||
| 26 | ); | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 3 | has created_at => ( | |||||||||||||
| 29 | is => 'ro', | ||||||||||||||
| 30 | isa => Datetime, | ||||||||||||||
| 31 | predicate => 'has_created_at', | ||||||||||||||
| 32 | coerce => 1, | ||||||||||||||
| 33 | required => 1, | ||||||||||||||
| 34 | ); | ||||||||||||||
| 35 | |||||||||||||||
| 36 | has is_work_in_progress => ( | ||||||||||||||
| 37 | is => 'ro', | ||||||||||||||
| 38 | isa => Bool, | ||||||||||||||
| 39 | lazy => 1, | ||||||||||||||
| 40 | default => sub { | ||||||||||||||
| 41 | 45 | ▶ | return shift->title =~ m{\A\[?WIP\]?}; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 42 | }, | ||||||||||||||
| 43 | 3 | ); | |||||||||||||
| 44 | |||||||||||||||
| 45 | 3 | has merged_at => ( | |||||||||||||
| 46 | is => 'ro', | ||||||||||||||
| 47 | isa => Datetime, | ||||||||||||||
| 48 | predicate => 'is_merged', | ||||||||||||||
| 49 | coerce => 1, | ||||||||||||||
| 50 | ); | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 3 | has number => ( | |||||||||||||
| 53 | is => 'ro', | ||||||||||||||
| 54 | isa => Int, | ||||||||||||||
| 55 | required => 1, | ||||||||||||||
| 56 | documentation => 'issue number in the GitHub url' | ||||||||||||||
| 57 | ); | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 3 | has title => ( | |||||||||||||
| 60 | is => 'ro', | ||||||||||||||
| 61 | isa => Str, | ||||||||||||||
| 62 | required => 1, | ||||||||||||||
| 63 | ); | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 3 | has state => ( | |||||||||||||
| 66 | is => 'ro', | ||||||||||||||
| 67 | isa => Str, | ||||||||||||||
| 68 | init_arg => undef, | ||||||||||||||
| 69 | lazy => 1, | ||||||||||||||
| 70 | builder => '_build_state', | ||||||||||||||
| 71 | ); | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 3 | has velocity => ( | |||||||||||||
| 74 | is => 'ro', | ||||||||||||||
| 75 | isa => Int, | ||||||||||||||
| 76 | init_arg => undef, | ||||||||||||||
| 77 | lazy => 1, | ||||||||||||||
| 78 | builder => '_build_velocity', | ||||||||||||||
| 79 | ); | ||||||||||||||
| 80 | |||||||||||||||
| 81 | sub is_open { | ||||||||||||||
| 82 | 43 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
is_open: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 83 | 43 | return $self->state eq 'open'; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | sub _build_age { | ||||||||||||||
| 87 | 45 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_age: called CC=3 SCAR=11.0
| |||||||||||||||
| 88 | |||||||||||||||
| 89 | 45 | ▶ | my $upper_bound | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 90 | = $self->is_merged ? $self->merged_at | ||||||||||||||
| 91 | : $self->is_closed ? $self->closed_at | ||||||||||||||
| 92 | : DateTime->now; | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 45 | return $upper_bound->delta_days( $self->created_at )->delta_days; | |||||||||||||
| 95 | } | ||||||||||||||
| 96 | |||||||||||||||
| 97 | sub _build_state { | ||||||||||||||
| 98 | 43 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_state: called CC=3 SCAR=11.0
| |||||||||||||||
| 99 | return | ||||||||||||||
| 100 | 43 | ▶ | $self->is_merged ? 'merged' | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 101 | : $self->is_closed ? 'closed' | ||||||||||||||
| 102 | : 'open'; | ||||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | # add points for merges in the first 30 days | ||||||||||||||
| 106 | # merges in 31 - 45 are neutral | ||||||||||||||
| 107 | # subtract after 45 days | ||||||||||||||
| 108 | |||||||||||||||
| 109 | sub _build_velocity { | ||||||||||||||
| 110 | 45 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_velocity: called CC=6 SCAR=17.9
| |||||||||||||||
| 111 | |||||||||||||||
| 112 | 45 | ▶ | return 0 if $self->is_work_in_progress; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 113 | |||||||||||||||
| 114 | 43 | ▶ | if ( $self->is_open ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | 4 | ▶ | return $self->age > 45 ? 45 - $self->age : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 39 | my $score = 0; | |||||||||||||
| 119 | 39 | ▶ | if ( $self->age < 31 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 120 | 31 | $score += round( 1.2**( 31 - $self->age ) ); | |||||||||||||
| 121 | } | ||||||||||||||
| 122 | elsif ( $self->age > 45 ) { | ||||||||||||||
| 123 | 7 | $score = 45 - $self->age; | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | 39 | return $score; | |||||||||||||
| 126 | } | ||||||||||||||
| 127 | |||||||||||||||
| 128 | 3 | 1; | |||||||||||||
| 129 | |||||||||||||||
| 130 | =pod | ||||||||||||||
| 131 | |||||||||||||||
| 132 | =encoding UTF-8 | ||||||||||||||
| 133 | |||||||||||||||
| 134 | =head1 NAME | ||||||||||||||
| 135 | |||||||||||||||
| 136 | GitHub::MergeVelocity::Repository::PullRequest - Encapsulate select data about GitHub pull requests | ||||||||||||||
| 137 | |||||||||||||||
| 138 | =head1 VERSION | ||||||||||||||
| 139 | |||||||||||||||
| 140 | version 0.000007 | ||||||||||||||
| 141 | |||||||||||||||
| 142 | =head1 AUTHOR | ||||||||||||||
| 143 | |||||||||||||||
| 144 | Olaf Alders <olaf@wundercounter.com> | ||||||||||||||
| 145 | |||||||||||||||
| 146 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 147 | |||||||||||||||
| 148 | This software is copyright (c) 2015 by Olaf Alders. | ||||||||||||||
| 149 | |||||||||||||||
| 150 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||
| 151 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||
| 152 | |||||||||||||||
| 153 | =cut | ||||||||||||||
| 154 | |||||||||||||||
| 155 | __END__ | ||||||||||||||
| 156 | |||||||||||||||
| 157 | # ABSTRACT: Encapsulate select data about GitHub pull requests | ||||||||||||||