API/Controller/Release.pm

filter: Statementstmt 29.6% 8 / 27 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 19.3% 11 / 57 SCAR 44.1
CC
11
Cov
16%
release
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 81.9
« API.pm ↑ Summary API/Controller/Upload.pm »
1 package CPAN::Testers::API::Controller::Release;
2 1 our $VERSION = '0.025';
3 # ABSTRACT: API for test reports collected by CPAN release
4  
5 #pod =head1 DESCRIPTION
6 #pod
7 #pod This API accesses summary data collected by CPAN release. So, if you
8 #pod just want to know how many PASS and FAIL reports a single distribution
9 #pod has for each version released, this is the best API.
10 #pod
11 #pod =head1 SEE ALSO
12 #pod
13 #pod =over
14 #pod
15 #pod =item L<CPAN::Testers::Schema::Result::Release>
16 #pod
17 #pod =item L<Mojolicious::Controller>
18 #pod
19 #pod =back
20 #pod
21 #pod =cut
22  
23 1 ▶use Mojo::Base 'Mojolicious::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use CPAN::Testers::API::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #pod =method release
27 #pod
28 #pod ### Requests:
29 #pod GET /v3/release
30 #pod GET /v3/release/dist/My-Dist
31 #pod GET /v3/release/author/PREACTION
32 #pod
33 #pod ### Optional query parameters (may be combined):
34 #pod # ?since=2016-01-01T12:34:00
35 #pod # ?maturity=stable
36 #pod # ?limit=2
37 #pod
38 #pod ### Response:
39 #pod 200 OK
40 #pod Content-Type: application/json
41 #pod
42 #pod [
43 #pod {
44 #pod "dist": "My-Dist",
45 #pod "version": "1.000",
46 #pod "pass": 34,
47 #pod "fail": 2,
48 #pod "na": 1,
49 #pod "unknown": 0
50 #pod }
51 #pod ]
52 #pod
53 #pod Get release data. Results can be limited by:
54 #pod
55 #pod =over
56 #pod
57 #pod =item *
58 #pod
59 #pod distribution (with the C<dist> key in the stash)
60 #pod
61 #pod =item *
62 #pod
63 #pod author (with the C<author> key in the stash)
64 #pod
65 #pod =item *
66 #pod
67 #pod date (with the C<since> query parameter)
68 #pod
69 #pod =item *
70 #pod
71 #pod maturity (with the C<maturity> query parameter)
72 #pod
73 #pod =item *
74 #pod
75 #pod limit (limits the total number of results sent with the C<limit> query parameter)
76 #pod
77 #pod =back
78 #pod
79 #pod Release data contains a summary of the pass, fail, na, and unknown test
80 #pod results created by stable Perls. Development Perls (odd-numbered 5.XX
81 #pod releases) are not included.
82 #pod
83 #pod =cut
84  
85 ▶sub release( $c ) {
Subroutine release: not called CC=11 SCAR=48.8
Pod documented
86 0 ▶ $c->openapi->valid_input or return;
Branch: 1 branch
BranchTrueFalseTotal
$c->openapi->valid_input or return 0 0 0
87  
88 0 my $rs = $c->schema->resultset( 'Release' );
89 0 $rs = $rs->search(
90 {
91 perlmat => 1, # only stable perls
92 patched => 1, # not patched perls
93 },
94 {
95 columns => [qw( dist version pass fail na unknown )],
96 # Only get hashrefs out
97 result_class => 'DBIx::Class::ResultClass::HashRefInflator',
98 }
99 );
100  
101 # Only allow "since" for "dist" and "author" because the query can
102 # not be optimized to return in a reasonable time.
103 0 ▶ if ( my $since = $c->param( 'since' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $since = $c->param("since")) 0 0 0
104 0 ▶ unless ( $c->validation->param( 'dist' ) || $c->validation->param( 'author' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->validation->param("dist") or $c->validation->param("author")) 0 0 0
Condition0%0/3
$c->validation->param("dist") or $c->validation->param("author")
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->validation->param("dist") or $c->validation->param("author")
$c->validation->param("dist") $c->validation->param("author")
Truth table0%0/3
A or B
A= $c->validation->param("dist")B= $c->validation->param("author")
ABresult
1X1
011
000
105 0 return $c->render_error( 400 => '"since" parameter not allowed' );
106 }
107 0 $rs = $rs->since( $since );
108 }
109  
110 0 ▶ if ( my $maturity = $c->param( 'maturity' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $maturity = $c->param("maturity")) 0 0 0
111 0 $rs = $rs->maturity( $maturity );
112 }
113  
114 0 my @results;
115 0 my $limit = $c->param( 'limit' );
116 # OpenAPI spec doesn't support property "minimum" on parameters
117 0 ▶ if ( $limit and $limit < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit and $limit < 1) 0 0 0
Condition0%0/3
$limit and $limit < 1
!ll&&!rl&&r
000
MC/DC0%0/2
$limit and $limit < 1
$limit $limit < 1
Truth table0%0/3
A and B
A= $limitB= $limit < 1
ABresult
0X0
100
111
118 0 return $c->render_error( 400 => 'The value for "limit" must be a positive integer' );
119 }
120 0 ▶ if ( $limit ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit) 0 0 0
121 0 $rs = $rs->slice( 0, $limit - 1 );
122 }
123  
124 0 ▶ if ( my $dist = $c->validation->param( 'dist' ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $dist = $c->validation->param('dist')) { } 0 0 0
elsif (my $author = $c->validation->param('author')) { } 0 0 0
125 0 $rs = $rs->by_dist( $dist );
126 }
127 elsif ( my $author = $c->validation->param( 'author' ) ) {
128 0 $rs = $rs->by_author( $author );
129 }
130  
131 0 return $c->stream_rs( $rs );
132 }
133  
134 1 1;
135  
136 __END__
137  
138 =pod
139  
140 =head1 NAME
141  
142 CPAN::Testers::API::Controller::Release - API for test reports collected by CPAN release
143  
144 =head1 VERSION
145  
146 version 0.025
147  
148 =head1 DESCRIPTION
149  
150 This API accesses summary data collected by CPAN release. So, if you
151 just want to know how many PASS and FAIL reports a single distribution
152 has for each version released, this is the best API.
153  
154 =head1 METHODS
155  
156 =head2 release
157  
158 ### Requests:
159 GET /v3/release
160 GET /v3/release/dist/My-Dist
161 GET /v3/release/author/PREACTION
162  
163 ### Optional query parameters (may be combined):
164 # ?since=2016-01-01T12:34:00
165 # ?maturity=stable
166 # ?limit=2
167  
168 ### Response:
169 200 OK
170 Content-Type: application/json
171  
172 [
173 {
174 "dist": "My-Dist",
175 "version": "1.000",
176 "pass": 34,
177 "fail": 2,
178 "na": 1,
179 "unknown": 0
180 }
181 ]
182  
183 Get release data. Results can be limited by:
184  
185 =over
186  
187 =item *
188  
189 distribution (with the C<dist> key in the stash)
190  
191 =item *
192  
193 author (with the C<author> key in the stash)
194  
195 =item *
196  
197 date (with the C<since> query parameter)
198  
199 =item *
200  
201 maturity (with the C<maturity> query parameter)
202  
203 =item *
204  
205 limit (limits the total number of results sent with the C<limit> query parameter)
206  
207 =back
208  
209 Release data contains a summary of the pass, fail, na, and unknown test
210 results created by stable Perls. Development Perls (odd-numbered 5.XX
211 releases) are not included.
212  
213 =head1 SEE ALSO
214  
215 =over
216  
217 =item L<CPAN::Testers::Schema::Result::Release>
218  
219 =item L<Mojolicious::Controller>
220  
221 =back
222  
223 =head1 AUTHOR
224  
225 Doug Bell <preaction@cpan.org>
226  
227 =head1 COPYRIGHT AND LICENSE
228  
229 This software is copyright (c) 2018 by Doug Bell.
230  
231 This is free software; you can redistribute it and/or modify it under
232 the same terms as the Perl 5 programming language system itself.
233  
234 =cut
« API.pm ↑ Summary API/Controller/Upload.pm »