TeamCity/Entity/Build.pm

filter: Statementstmt 100% 77 / 77 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 20 / 20 Podpod n/a totaltotal 98.0% 101 / 103 CC 5 SCAR 3.5
CC
5
Cov
98%
_build_artifacts_dir
3.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.4
« TeamCity.pm ↑ Summary TeamCity/Entity/Project.pm »
1 package WebService::TeamCity::Entity::Build;
2  
3 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '0.04';
9  
10 4 ▶use Archive::Zip;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use File::pushd qw( pushd );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Path::Tiny 0.086 qw( path tempdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Types::Standard qw( ArrayRef Bool Maybe InstanceOf Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use WebService::TeamCity::Entity::BuildType;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use WebService::TeamCity::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use WebService::TeamCity::Entity::TestOccurrence;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use WebService::TeamCity::Types qw( BuildStatus JSONBool );
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 has status => (
22 is => 'ro',
23 isa => BuildStatus,
24 required => 1,
25 );
26  
27 has build_type => (
28 is => 'ro',
29 isa => InstanceOf ['WebService::TeamCity::Entity::BuildType'],
30 lazy => 1,
31 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 $_[0]->_inflate_one(
33 $_[0]->_full_data->{build_type},
34 1 'BuildType',
35 );
36 },
37 4 );
38  
39 has test_occurrences => (
40 is => 'ro',
41 isa => InstanceOf ['WebService::TeamCity::Iterator'],
42 lazy => 1,
43 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 $_[0]->_iterator_for(
45 $_[0]->client->base_uri
46 . $_[0]->_full_data->{test_occurrences}{href},
47 1 'test_occurrence',
48 'TestOccurrence',
49 );
50 },
51 4 );
52  
53 4 has branch_name => (
54 is => 'ro',
55 isa => Str,
56 predicate => 'has_branch_name',
57 );
58  
59 4 has default_branch => (
60 is => 'ro',
61 isa => Bool | JSONBool,
62 predicate => 'has_default_branch',
63 );
64  
65 4 has number => (
66 is => 'ro',
67 isa => Str,
68 required => 1,
69 );
70  
71 4 has state => (
72 is => 'ro',
73 isa => Str,
74 required => 1,
75 );
76  
77 has queued_date => (
78 is => 'ro',
79 isa => InstanceOf ['DateTime'],
80 lazy => 1,
81 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
82 1 $_[0]->_parse_datetime( $_[0]->_full_data->{queued_date} );
83 },
84 4 );
85  
86 has start_date => (
87 is => 'ro',
88 isa => Maybe [ InstanceOf ['DateTime'] ],
89 lazy => 1,
90 1 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
91 1 my $full = $_[0]->_full_data;
92 1 ▶ return unless $full->{start_date};
Branch: 1 branch
BranchTrueFalseTotal
unless $full->{"start_date"} 0 1 1
93 1 $_[0]->_parse_datetime( $full->{start_date} );
94 },
95 4 );
96  
97 has finish_date => (
98 is => 'ro',
99 isa => Maybe [ InstanceOf ['DateTime'] ],
100 lazy => 1,
101 1 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
102 1 my $full = $_[0]->_full_data;
103 1 ▶ return unless $full->{finish_date};
Branch: 1 branch
BranchTrueFalseTotal
unless $full->{"finish_date"} 0 1 1
104 1 $_[0]->_parse_datetime( $full->{finish_date} );
105 },
106 4 );
107  
108 4 has _artifacts_dir => (
109 is => 'ro',
110 isa => ArrayRef,
111 lazy => 1,
112 builder => '_build_artifacts_dir',
113 );
114  
115 # has statistics
116  
117 # has properties
118  
119 # has related_issues
120  
121 # has agent
122  
123 # has revisions
124  
125 # has changes
126  
127 # has triggered
128  
129 # has last_changes
130  
131 # has problem_occurences
132  
133 4 with(
134 'WebService::TeamCity::Entity',
135 'WebService::TeamCity::Entity::HasID',
136 'WebService::TeamCity::Entity::HasStatus',
137 'WebService::TeamCity::Entity::HasWebURL',
138 );
139  
140 1 ▶sub artifacts_dir { $_[0]->_artifacts_dir->[1] }
Subroutine artifacts_dir: called CC=1 SCAR=0.0
141  
142 1 ▶sub _build_artifacts_dir {
Subroutine _build_artifacts_dir: called CC=3 SCAR=11.0
143 1 my $self = shift;
144  
145 1 my $tempdir = tempdir( CLEANUP => 1 );
146  
147 1 ( my $base = $self->href ) =~ s{/$}{};
148  
149 1 my $zip = $tempdir->child('artifacts.zip');
150 1 $self->client->make_request(
151 uri => $self->client->uri_for( $base . '/artifacts/archived' ),
152 file => $zip->stringify,
153 );
154  
155 1 my $dir = $tempdir->child('artifacts');
156 1 $dir->mkpath(
157 {
158 verbose => 0,
159 ## no critic (ValuesAndExpressions::ProhibitLeadingZeros)
160 mode => 0755,
161 }
162 );
163  
164 # The zip file downloaded from TC may have very odd permissions for
165 # directories (dirs without execute bits on). The
166 # Archive::Zip::Archive->extractTree method simply blows up because of
167 # this. It makes a parent dir and then cannot write the files it contains
168 # into that directory.
169 #
170 # So we go through each member in the zip and extract it ourselves, then
171 # change the permissions to something sane.
172 1 my $az = Archive::Zip->new;
173 1 $az->read( $zip->stringify );
174  
175 1 my $pushed = pushd($dir);
176  
177 1 for my $member ( $az->members ) {
178 3 $az->extractMember($member);
179 3 my $extracted = $dir->child( $member->fileName );
180 ## no critic (ValuesAndExpressions::ProhibitLeadingZeros)
181 3 ▶ $extracted->chmod( $extracted->is_dir ? 0755 : 0644 );
Branch: 1 branch
BranchTrueFalseTotal
$extracted->is_dir ? : 1 2 3
182 }
183  
184 # We have to save the temp dir in the object or it gets cleaned up when
185 # $tempdir goes out of scope.
186 1 return [ $tempdir, $dir ];
187 }
188  
189 4 1;
190  
191 # ABSTRACT: A single TeamCity build
192  
193 __END__
« TeamCity.pm ↑ Summary TeamCity/Entity/Project.pm »