File Coverage

blib/lib/CPAN/Testers/API/Controller/Report.pm
Criterion Covered Total %
statement 23 23 100.0
branch 5 6 83.3
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 34 35 97.1


line stmt bran cond sub pod time code
1             package CPAN::Testers::API::Controller::Report;
2             our $VERSION = '0.020';
3             # ABSTRACT: Work with raw test reports
4              
5             #pod =head1 DESCRIPTION
6             #pod
7             #pod This API allows working directly with the JSON report documents
8             #pod submitted by the army of testers of CPAN.
9             #pod
10             #pod =head1 SEE ALSO
11             #pod
12             #pod L<CPAN::Testers::Schema::Result::TestReport>, L<Mojolicious::Controller>
13             #pod
14             #pod =cut
15              
16 1     1   7209 use Mojo::Base 'Mojolicious::Controller';
  1         4  
  1         13  
17 1     1   339 use CPAN::Testers::API::Base;
  1         3  
  1         21  
18              
19             #pod =method report_post
20             #pod
21             #pod ### Requests:
22             #pod POST /v3/report
23             #pod { ... }
24             #pod
25             #pod ### Response:
26             #pod 201 Created
27             #pod { "id": "..." }
28             #pod
29             #pod Submit a new CPAN Testers report. This is used by testers when they're
30             #pod finished running a test.
31             #pod
32             #pod =cut
33              
34 2     2 1 3728 sub report_post( $c ) {
  2         8  
  2         8  
35 2         15 $c->app->log->debug( 'Submitting Report: ' . $c->req->body );
36 2 100       227 $c->openapi->valid_input or return;
37 1         26494 my $report = $c->validation->param( 'report' );
38 1         80 my $row = $c->schema->resultset( 'TestReport' )->create( {
39             report => $report,
40             } );
41 1         16299 return $c->render(
42             status => 201,
43             openapi => {
44             id => $row->id,
45             },
46             );
47             }
48              
49             #pod =method report_get
50             #pod
51             #pod ### Requests:
52             #pod GET /v3/report/:guid
53             #pod
54             #pod ### Response
55             #pod 200 OK
56             #pod { "id": "...", ... }
57             #pod
58             #pod Get a single CPAN Testers report from the database.
59             #pod
60             #pod =cut
61              
62 2     2 1 7946 sub report_get( $c ) {
  2         7  
  2         4  
63 2 50       19 $c->openapi->valid_input or return;
64 2         2325 my $id = $c->validation->param( 'id' );
65 2         80 my $row = $c->schema->resultset( 'TestReport' )->find( $id );
66 2 100       8369 if ( !$row ) {
67 1         40 return $c->render(
68             status => 404,
69             openapi => {
70             errors => [
71             {
72             message => 'Report ID not found',
73             path => '/id',
74             },
75             ],
76             },
77             );
78             }
79 1         40 return $c->render(
80             openapi => $row->report,
81             );
82             }
83              
84             1;
85              
86             __END__
87              
88             =pod
89              
90             =head1 NAME
91              
92             CPAN::Testers::API::Controller::Report - Work with raw test reports
93              
94             =head1 VERSION
95              
96             version 0.020
97              
98             =head1 DESCRIPTION
99              
100             This API allows working directly with the JSON report documents
101             submitted by the army of testers of CPAN.
102              
103             =head1 METHODS
104              
105             =head2 report_post
106              
107             ### Requests:
108             POST /v3/report
109             { ... }
110              
111             ### Response:
112             201 Created
113             { "id": "..." }
114              
115             Submit a new CPAN Testers report. This is used by testers when they're
116             finished running a test.
117              
118             =head2 report_get
119              
120             ### Requests:
121             GET /v3/report/:guid
122              
123             ### Response
124             200 OK
125             { "id": "...", ... }
126              
127             Get a single CPAN Testers report from the database.
128              
129             =head1 SEE ALSO
130              
131             L<CPAN::Testers::Schema::Result::TestReport>, L<Mojolicious::Controller>
132              
133             =head1 AUTHOR
134              
135             Doug Bell <preaction@cpan.org>
136              
137             =head1 COPYRIGHT AND LICENSE
138              
139             This software is copyright (c) 2016 by Doug Bell.
140              
141             This is free software; you can redistribute it and/or modify it under
142             the same terms as the Perl 5 programming language system itself.
143              
144             =cut