File Coverage

blib/lib/App/GHPT/WorkSubmitter/ChangedFiles.pm
Criterion Covered Total %
statement 9 47 19.1
branch 0 8 0.0
condition n/a
subroutine 3 13 23.0
pod 5 5 100.0
total 17 73 23.2


line stmt bran cond sub pod time code
1              
2             use App::GHPT::Wrapper::OurMoose;
3 1     1   8  
  1         3  
  1         10  
4             our $VERSION = '2.000000';
5              
6             use List::Util 1.44 qw( any uniq );
7 1     1   13 use App::GHPT::Types qw( ArrayRef HashRef Str );
  1         29  
  1         86  
8 1     1   6  
  1         2  
  1         16  
9             has [
10             qw(
11             added_files
12             all_files
13             deleted_files
14             modified_files
15             )
16             ] => (
17             is => 'ro',
18             isa => ArrayRef [Str],
19             required => 1,
20             );
21              
22             has _file_exists_hash => (
23             is => 'ro',
24             isa => HashRef,
25             lazy => 1,
26             builder => '_build_file_exists_hash',
27             );
28              
29             return +{ map { $_ => 1 } $self->all_files->@* };
30 0     0     }
  0            
  0            
31 0            
  0            
32             return [ uniq sort $self->added_files->@*, $self->modified_files->@* ];
33             }
34 0     0 1    
  0            
  0            
35 0           return any { $_ =~ $regex } $self->changed_files->@*;
36             }
37              
38 0     0 1   return grep { $_ =~ $regex } $self->changed_files->@*;
  0            
  0            
  0            
39 0     0     }
  0            
40              
41             return $self->_file_exists_hash->{$path};
42 0     0 1   }
  0            
  0            
  0            
43 0            
  0            
44             # this is inefficently written, but it shouldn't really make any difference
45             # for the number of files we're talking about here
46 0     0 1   return 'A' if any { $_ eq $path } $self->added_files->@*;
  0            
  0            
  0            
47 0           return 'M' if any { $_ eq $path } $self->modified_files->@*;
48             return 'D' if any { $_ eq $path } $self->deleted_files->@*;
49             return q{ } if $self->file_exists($path);
50             return undef;
51             }
52 0     0 1    
  0            
  0            
  0            
53 0 0   0     __PACKAGE__->meta->make_immutable;
  0            
54 0 0   0      
  0            
55 0 0   0     1;
  0            
56 0 0          
57 0           # ABSTRACT: Contains all the files that were modified or added in a branch
58              
59              
60             =pod
61              
62             =encoding UTF-8
63              
64             =head1 NAME
65              
66             App::GHPT::WorkSubmitter::ChangedFiles - Contains all the files that were modified or added in a branch
67              
68             =head1 VERSION
69              
70             version 2.000000
71              
72             =head1 SYNOPSIS
73              
74             =head1 DESCRIPTION
75              
76             A class that represents what files were added, modified or deleted in a
77             branch, as well as what files exist in the branch.
78              
79             Normally constructed by L<App::GHPT::WorkSubmitter::ChangedFilesFactory>.
80              
81             =for test_synopsis use v5.20;
82              
83             my $factory = App::GHPT::WorkSubmitter::ChangedFilesFactory->new(
84             merge_to_branch_name => 'main',
85             );
86              
87             my $changed_files = $factory->changed_files;
88              
89             # print out all modified / added file in this branch
90             say for $changed_files->changed_files->@*;
91              
92             =head1 ATTRIBUTES
93              
94             =head2 added_files
95              
96             All files added in this branch.
97              
98             Arrayref of String. Required.
99              
100             =head2 modified_files
101              
102             All files modified in this branch (excluding those that were added in this
103             branch)
104              
105             Arrayref of String. Required.
106              
107             =head2 deleted_files
108              
109             All files deleted in this branch.
110              
111             Arrayref of String. Required.
112              
113             =head2 all_files
114              
115             All files in this branch (including those created before the branch was
116             branched.) i.e. every file that you'd get from a fresh checkout of this
117             branch.
118              
119             Arrayref of String. Required.
120              
121             =head1 METHODS
122              
123             =head2 $changed->changed_files
124              
125             All changed files (i.e. all files that were either added or modified in
126             this branch.) Returns Arrayref of Strings.
127              
128             =head2 $changed->changed_files_match( $regex )
129              
130             Returns true iff any of the changed files filenames match the passed regex
131              
132             =head2 $changed->changed_files_matching( $regex )
133              
134             Returns a list of changed files filenames matching the passed regex
135              
136             =head2 $changed->file_exists( $path )
137              
138             Does the passed file exist on the branch (i.e. if you were to do a fresh
139             checkout of this branch would the file be present)
140              
141             =head2 $changed->file_status( $path )
142              
143             Returns the file status. This is either C<A> (added), C<D> (deleted), C<M>
144             (modified), C< > (exists, not modified) or undef (doesn't exist).
145              
146             =head1 SUPPORT
147              
148             Bugs may be submitted through L<https://github.com/maxmind/App-GHPT/issues>.
149              
150             =head1 AUTHORS
151              
152             =over 4
153              
154             =item *
155              
156             Mark Fowler <mark@twoshortplanks.com>
157              
158             =item *
159              
160             Dave Rolsky <autarch@urth.org>
161              
162             =back
163              
164             =head1 COPYRIGHT AND LICENSE
165              
166             This software is Copyright (c) 2022 by MaxMind, Inc.
167              
168             This is free software, licensed under:
169              
170             The Artistic License 2.0 (GPL Compatible)
171              
172             =cut