API/Controller/Summary.pm

filter: Statementstmt 28.5% 8 / 28 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 40.0% 2 / 5 Podpod 100% 1 / 1 totaltotal 13.5% 11 / 81 SCAR 52.4
CC
16
Cov
12%
summary
272.0
__ANON__
2.0
_format_date
2.0
CRAP 188.6
↑ Summary API.pm »
1 package CPAN::Testers::API::Controller::Summary;
2 1 our $VERSION = '0.025';
3 # ABSTRACT: API for test report summary data
4  
5 #pod =head1 DESCRIPTION
6 #pod
7 #pod This API accesses the test report summaries, which are a few fields picked out of
8 #pod the larger test report data structure that are useful for reporting.
9 #pod
10 #pod =head1 SEE ALSO
11 #pod
12 #pod =over
13 #pod
14 #pod =item L<CPAN::Testers::Schema::Result::Stats>
15 #pod
16 #pod =item L<Mojolicious::Controller>
17 #pod
18 #pod =back
19 #pod
20 #pod =cut
21  
22 1 ▶use Mojo::Base 'Mojolicious::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use CPAN::Testers::API::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #pod =method summary
26 #pod
27 #pod ### Requests:
28 #pod GET /v3/summary/My-Dist
29 #pod GET /v3/summary/My-Dist/1.000
30 #pod
31 #pod ### Response:
32 #pod 200 OK
33 #pod Content-Type: application/json
34 #pod
35 #pod [
36 #pod {
37 #pod "guid": "00000000-0000-0000-0000-0000000000001",
38 #pod "id": 1,
39 #pod "grade": "pass",
40 #pod "dist": "My-Dist",
41 #pod "version": "1.000",
42 #pod "tester": "doug@example.com (Doug Bell)",
43 #pod "platform": "darwin",
44 #pod "perl": "5.22.0",
45 #pod "osname": "darwin",
46 #pod "osvers": "10.8.0"
47 #pod }
48 #pod ]
49 #pod
50 #pod Get test report summary data for the given distribution and version.
51 #pod
52 #pod Report summary data contains a select set of fields from the full test
53 #pod report. These fields are the most useful ones for building aggregate
54 #pod reporting and graphs for dashboards.
55 #pod
56 #pod =cut
57  
58 ▶sub summary( $c ) {
Subroutine summary: not called CC=16 SCAR=56.1
Pod documented
59 0 ▶ $c->openapi->valid_input or return;
Branch: 1 branch
BranchTrueFalseTotal
$c->openapi->valid_input or return 0 0 0
60  
61 0 my $dist = $c->validation->param( 'dist' );
62 0 my $version = $c->validation->param( 'version' );
63 0 my $grade = $c->validation->param( 'grade' );
64 0 my $perl = $c->validation->every_param( 'perl' );
65 0 my $osname = $c->validation->every_param( 'osname' );
66  
67 0 ▶ if ( !$dist && !$version && ( !$perl || !@$perl ) && ( !$osname || !@$osname ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dist or $version or $perl and @$perl or $osname and @$osname) 0 0 0
Condition0%0/15
$dist or $version or $perl and @$perl or $osname and @$osname
l!l&&r!l&&!r
000
$dist or $version or $perl and @$perl
l!l&&r!l&&!r
000
$dist or $version
l!l&&r!l&&!r
000
$perl and @$perl
!ll&&!rl&&r
000
$osname and @$osname
!ll&&!rl&&r
000
MC/DC0%0/6
$dist or $version or $perl and @$perl or $osname and @$osname
$dist $version $perl @$perl $osname @$osname
Truth table0%0/9
A or B or C and D or E and F
A= $distB= $versionC= $perlD= @$perlE= $osnameF= @$osname
ABCDEFresult
1XXXXX1
01XXXX1
0011XX1
000X111
0010111
000X0X0
000X100
00100X0
0010100
68 0 return $c->render_error( 400, "You must provide one of 'perl' or 'osname'" );
69 }
70  
71 0 my $rs = $c->schema->resultset( 'Stats' );
72 0 ▶ $rs = $rs->search(
Branch: 5 branches
BranchTrueFalseTotal
$dist ? : 0 0 0
$version ? : 0 0 0
$perl && @$perl ? : 0 0 0
$osname && @$osname ? : 0 0 0
$grade ? : 0 0 0
Condition0%0/6
$perl and @$perl
!ll&&!rl&&r
000
$osname and @$osname
!ll&&!rl&&r
000
MC/DC0%0/2
$perl and @$perl
$perl @$perl
MC/DC0%0/2
$osname and @$osname
$osname @$osname
Truth table0%0/3
A and B
A= $perlB= @$perl
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $osnameB= @$osname
ABresult
0X0
100
111
73 {
74 ( $dist ? ( dist => $dist ) : () ),
75 ( $version ? ( version => $version ) : () ),
76 ( $perl && @$perl ? ( perl => $perl ) : () ),
77 ( $osname && @$osname ? ( osname => $osname ) : () ),
78 ( $grade ? ( state => $grade ) : () ),
79 },
80 {
81 columns => [qw( guid fulldate state tester dist version platform perl osname osvers )],
82 # Only get hashrefs out
83 result_class => 'DBIx::Class::ResultClass::HashRefInflator',
84 }
85 );
86  
87 0 ▶ if ( my $since = $c->validation->param( 'since' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $since = $c->validation->param("since")) 0 0 0
88 0 $rs = $rs->since( $since );
89 }
90  
91 $c->stream_rs( $rs, sub {
92 0 ▶ my $result = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
93 0 $result->{grade} = delete $result->{state};
94 0 $result->{date} = _format_date( delete $result->{fulldate} );
95 0 $result->{reporter} = delete $result->{tester};
96 0 return $result;
97 0 } );
98 }
99  
100 ▶sub _format_date( $fulldate ) {
Subroutine _format_date: not called CC=1 SCAR=6.9
101 0 my ( $y, $m, $d, $h, $n ) = $fulldate =~ /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/;
102 0 return "$y-$m-${d}T$h:$n:00Z";
103 }
104  
105 1 1;
106  
107 __END__
108  
109 =pod
110  
111 =head1 NAME
112  
113 CPAN::Testers::API::Controller::Summary - API for test report summary data
114  
115 =head1 VERSION
116  
117 version 0.025
118  
119 =head1 DESCRIPTION
120  
121 This API accesses the test report summaries, which are a few fields picked out of
122 the larger test report data structure that are useful for reporting.
123  
124 =head1 METHODS
125  
126 =head2 summary
127  
128 ### Requests:
129 GET /v3/summary/My-Dist
130 GET /v3/summary/My-Dist/1.000
131  
132 ### Response:
133 200 OK
134 Content-Type: application/json
135  
136 [
137 {
138 "guid": "00000000-0000-0000-0000-0000000000001",
139 "id": 1,
140 "grade": "pass",
141 "dist": "My-Dist",
142 "version": "1.000",
143 "tester": "doug@example.com (Doug Bell)",
144 "platform": "darwin",
145 "perl": "5.22.0",
146 "osname": "darwin",
147 "osvers": "10.8.0"
148 }
149 ]
150  
151 Get test report summary data for the given distribution and version.
152  
153 Report summary data contains a select set of fields from the full test
154 report. These fields are the most useful ones for building aggregate
155 reporting and graphs for dashboards.
156  
157 =head1 SEE ALSO
158  
159 =over
160  
161 =item L<CPAN::Testers::Schema::Result::Stats>
162  
163 =item L<Mojolicious::Controller>
164  
165 =back
166  
167 =head1 AUTHOR
168  
169 Doug Bell <preaction@cpan.org>
170  
171 =head1 COPYRIGHT AND LICENSE
172  
173 This software is copyright (c) 2018 by Doug Bell.
174  
175 This is free software; you can redistribute it and/or modify it under
176 the same terms as the Perl 5 programming language system itself.
177  
178 =cut
↑ Summary API.pm »