/
Release.pm
111 lines (88 loc) · 2.87 KB
/
Release.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package CPAN::Testers::API::Controller::Release;
our $VERSION = '0.002';
# ABSTRACT: API for test reports collected by CPAN release
=head1 DESCRIPTION
This API accesses summary data collected by CPAN release. So, if you
just want to know how many PASS and FAIL reports a single distribution
has for each version released, this is the best API.
=head1 SEE ALSO
=over
=item L<CPAN::Testers::Schema::Result::Release>
=item L<Mojolicious::Controller>
=back
=cut
use Mojo::Base 'Mojolicious::Controller';
use CPAN::Testers::API::Base;
=method release
### Requests:
GET /v1/release
GET /v1/release?since=2016-01-01T12:34:00Z
GET /v1/release/dist/My-Dist
GET /v1/release/dist/My-Dist?since=2016-01-01T12:34:00Z
GET /v1/release/author/PREACTION
GET /v1/release/author/PREACTION?since=2016-01-01T12:34:00Z
### Response:
200 OK
Content-Type: application/json
[
{
"dist": "My-Dist",
"version": "1.000",
"pass": 34,
"fail": 2,
"na": 1,
"unknown": 0
}
]
Get release data. Results can be limited by distribution (with the
C<dist> key in the stash), by author (with the C<author> key in the
stash), and by date (with the C<since> query parameter).
Release data contains a summary of the pass, fail, na, and unknown test
results created by stable Perls. Development Perls (odd-numbered 5.XX
releases) are not included.
=cut
sub release( $c ) {
$c->openapi->valid_input or return;
my $rs = $c->schema->resultset( 'Release' );
$rs = $rs->search(
{
perlmat => 1, # only stable perls
patched => 1, # not patched perls
},
{
columns => [qw( dist version pass fail na unknown )],
# Only get hashrefs out
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
}
);
# Only allow "since" for "dist" and "author" because the query can
# not be optimized to return in a reasonable time.
if ( my $since = $c->param( 'since' ) ) {
unless ( $c->validation->param( 'dist' ) || $c->validation->param( 'author' ) ) {
return $c->render_error( 400 => '"since" parameter not allowed' );
}
$rs = $rs->since( $since );
}
my @results;
if ( my $dist = $c->validation->param( 'dist' ) ) {
$rs = $rs->by_dist( $dist );
@results = $rs->all;
if ( !@results ) {
return $c->render_error( 404, sprintf 'Distribution "%s" not found', $dist );
}
}
elsif ( my $author = $c->validation->param( 'author' ) ) {
@results = $rs->by_author( $author )->all;
if ( !@results ) {
return $c->render_error( 404, sprintf 'Author "%s" not found', $author );
}
}
else {
@results = $rs->all;
}
return $c->render(
openapi => \@results,
);
}
1;
__END__