File tree 12 files changed +197
-67
lines changed
12 files changed +197
-67
lines changed Original file line number Diff line number Diff line change
1
+ package MetaCPAN::API::Controller::Cover ;
2
+
3
+ use Mojo::Base ' Mojolicious::Controller' ;
4
+
5
+ sub lookup {
6
+ my $c = shift ;
7
+ return unless $c -> openapi-> valid_input;
8
+ my $args = $c -> validation-> output;
9
+
10
+ my $results = $c -> model-> cover-> find_release_coverage( $args -> {name } );
11
+ return $c -> render( openapi => $results ) if $results ;
12
+ $c -> rendered(404);
13
+ }
14
+
15
+ 1;
16
+
Original file line number Diff line number Diff line change
1
+ package MetaCPAN::API::Model::Cover ;
2
+
3
+ use MetaCPAN::Moose;
4
+
5
+ with ' MetaCPAN::API::Model::Role::ES' ;
6
+
7
+ sub find_release_coverage {
8
+ my ( $self , $release ) = @_ ;
9
+
10
+ my $query = +{ term => { release => $release } };
11
+
12
+ my $res = $self -> _run_query(
13
+ index => ' cover' ,
14
+ type => ' cover' ,
15
+ body => {
16
+ query => $query ,
17
+ size => 999,
18
+ }
19
+ );
20
+ $res -> {hits }{total } or return {};
21
+
22
+ return +{
23
+ %{ $res -> {hits }{hits }[0]{_source } },
24
+ url => " http://cpancover.com/latest/$release /index.html" ,
25
+ };
26
+ }
27
+
28
+ __PACKAGE__ -> meta-> make_immutable;
29
+
30
+ 1;
31
+
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ use MetaCPAN::Model::Search ();
10
10
# New models
11
11
use MetaCPAN::API::Model::User ();
12
12
use MetaCPAN::API::Model::Download ();
13
+ use MetaCPAN::API::Model::Cover ();
13
14
14
15
has app => sub { Carp::croak ' app is required' }, weak => 1;
15
16
@@ -31,6 +32,11 @@ has user => sub {
31
32
return MetaCPAN::API::Model::User-> new( es => $self -> app-> es );
32
33
};
33
34
35
+ has cover => sub {
36
+ my $self = shift ;
37
+ return MetaCPAN::API::Model::Cover-> new( es => $self -> app-> es );
38
+ };
39
+
34
40
sub register {
35
41
my ( $plugin , $app , $conf ) = @_ ;
36
42
$plugin -> app($app );
@@ -39,6 +45,7 @@ sub register {
39
45
$app -> helper( ' model.download' => sub { $plugin -> download } );
40
46
$app -> helper( ' model.search' => sub { $plugin -> search } );
41
47
$app -> helper( ' model.user' => sub { $plugin -> user } );
48
+ $app -> helper( ' model.cover' => sub { $plugin -> cover } );
42
49
}
43
50
44
51
1;
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ use namespace::autoclean;
5
5
6
6
use Cpanel::JSON::XS qw( decode_json ) ;
7
7
use Log::Contextual qw( :log :dlog ) ;
8
- use MetaCPAN::Types qw( Bool Uri) ;
8
+ use MetaCPAN::Types qw( Bool Str Uri) ;
9
+ use Path::Class qw( file ) ;
9
10
10
11
with ' MetaCPAN::Role::Script' , ' MooseX::Getopt' ;
11
12
@@ -30,6 +31,14 @@ has test => (
30
31
documentation => ' Test mode (pulls smaller development data set)' ,
31
32
);
32
33
34
+ has json_file => (
35
+ is => ' ro' ,
36
+ isa => Str,
37
+ default => 0,
38
+ documentation =>
39
+ ' Path to JSON file to be read instead of URL (for testing)' ,
40
+ );
41
+
33
42
my %valid_keys
34
43
= map { $_ => 1 } qw< branch condition statement subroutine total > ;
35
44
@@ -96,6 +105,11 @@ sub index_cover_data {
96
105
sub retrieve_cover_data {
97
106
my $self = shift ;
98
107
108
+ if ( $self -> json_file ) {
109
+ my $file = file( $self -> json_file );
110
+ return decode_json( $file -> slurp );
111
+ }
112
+
99
113
my $url = $self -> test ? $self -> cover_dev_url : $self -> cover_url;
100
114
101
115
log_info { ' Fetching data from ' , $url };
@@ -129,4 +143,3 @@ Retrieves the CPAN cover data from its source and
129
143
updates our ES information.
130
144
131
145
=cut
132
-
Original file line number Diff line number Diff line change
1
+ ---
2
+
3
+ ErrorModel :
4
+ type : " object"
5
+ required :
6
+ - " code"
7
+ - " message"
8
+ properties :
9
+ code :
10
+ type : " integer"
11
+ format : " int32"
12
+ message :
13
+ type : " string"
Original file line number Diff line number Diff line change
1
+ ---
2
+
3
+ cover :
4
+ get :
5
+ tags :
6
+ - Coverage
7
+ operationId : cover
8
+ x-mojo-to : Cover#lookup
9
+ summary : Get coverage details about a release
10
+ parameters :
11
+ - name : name
12
+ in : path
13
+ description : |
14
+ The name of the Release
15
+ type : string
16
+ required : true
17
+ # tell Mojolicious to use relaxed placeholders when
18
+ # parsing this parameter (dots are allowed)
19
+ x-mojo-placeholder : " #"
20
+ responses :
21
+ 200 :
22
+ description : Release response
23
+ schema :
24
+ type : object
25
+ properties :
26
+ name :
27
+ type : string
28
+ default :
29
+ description : " unexpected error"
30
+ schema :
31
+ $ref : " ../definitions/common.yml#/ErrorModel"
Original file line number Diff line number Diff line change 22
22
$ref : " requests/search.yml#/search_web"
23
23
/search/first :
24
24
$ref : " requests/search.yml#/search_first"
25
+ /cover/{name} :
26
+ $ref : " requests/cover.yml#/cover"
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ $server->prepare_user_test_data;
105
105
$server -> index_cpantesters;
106
106
$server -> index_mirrors;
107
107
$server -> index_favorite;
108
+ $server -> index_cover;
108
109
109
110
ok(
110
111
MetaCPAN::Script::Tickets-> new_with_options(
Original file line number Diff line number Diff line change
1
+ use Mojo::Base -strict;
2
+ use lib ' t/lib' ;
3
+
4
+ use Test::More;
5
+ use Test::Mojo;
6
+ use Mojo::JSON qw( true false) ;
7
+
8
+ use MetaCPAN::Model::Search ();
9
+ use MetaCPAN::TestServer ();
10
+ my $server = MetaCPAN::TestServer-> new;
11
+
12
+ my $t = Test::Mojo-> new(
13
+ ' MetaCPAN::API' => {
14
+ es => $server -> es_client,
15
+ secret => ' just a test' ,
16
+ }
17
+ );
18
+
19
+ my %expect = (
20
+ ' MetaFile-Both-1.1' => {
21
+ criteria => {
22
+ branch => ' 12.50' ,
23
+ condition => ' 0.00' ,
24
+ statement => ' 63.64' ,
25
+ subroutine => ' 71.43' ,
26
+ total => ' 46.51' ,
27
+ },
28
+ distribution => ' MetaFile-Both' ,
29
+ release => ' MetaFile-Both-1.1' ,
30
+ url => ' http://cpancover.com/latest/MetaFile-Both-1.1/index.html' ,
31
+ version => ' 1.1' ,
32
+ },
33
+ ' Pod-With-Generator-1' => {
34
+ criteria => {
35
+ branch => ' 78.95' ,
36
+ condition => ' 46.67' ,
37
+ statement => ' 95.06' ,
38
+ subroutine => ' 100.00' ,
39
+ total => ' 86.58' ,
40
+ },
41
+ distribution => ' Pod-With-Generator' ,
42
+ release => ' Pod-With-Generator-1' ,
43
+ url => ' http://cpancover.com/latest/Pod-With-Generator-1/index.html' ,
44
+ version => ' 1' ,
45
+ },
46
+ );
47
+
48
+ for my $release ( keys %expect ) {
49
+ my $expected = $expect {$release };
50
+ subtest " Check $release " => sub {
51
+
52
+ $t -> get_ok(" /v1/cover/$release " )-> status_is(200)-> json_is($expected )
53
+ -> or ( sub { diag $t -> tx-> res-> dom } );
54
+
55
+ };
56
+ }
57
+ done_testing;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use MetaCPAN::Moose;
4
4
5
5
use MetaCPAN::DarkPAN ();
6
6
use MetaCPAN::Script::Author ();
7
+ use MetaCPAN::Script::Cover ();
7
8
use MetaCPAN::Script::CPANTestersAPI ();
8
9
use MetaCPAN::Script::Favorite ();
9
10
use MetaCPAN::Script::First ();
@@ -226,6 +227,14 @@ sub index_mirrors {
226
227
' index mirrors' );
227
228
}
228
229
230
+ sub index_cover {
231
+ my $self = shift ;
232
+
233
+ local @ARGV = ( ' cover' , ' --json_file' , ' t/var/cover.json' );
234
+ ok( MetaCPAN::Script::Cover-> new_with_options( $self -> _config )-> run,
235
+ ' index cover' );
236
+ }
237
+
229
238
sub index_permissions {
230
239
my $self = shift ;
231
240
Original file line number Diff line number Diff line change @@ -7,31 +7,31 @@ use MetaCPAN::TestHelpers qw( decode_json_ok );
7
7
use Test::More;
8
8
9
9
my %expect = (
10
- ' Devel-GoFaster-0.000 ' => {
10
+ ' MetaFile-Both-1.1 ' => {
11
11
criteria => {
12
12
branch => ' 12.50' ,
13
13
condition => ' 0.00' ,
14
14
statement => ' 63.64' ,
15
15
subroutine => ' 71.43' ,
16
16
total => ' 46.51' ,
17
17
},
18
- distribution => ' Devel-GoFaster ' ,
19
- release => ' Devel-GoFaster-0.000 ' ,
20
- url => ' http://cpancover.com/latest/Devel-GoFaster-0.000 /index.html' ,
21
- version => ' 0.000 ' ,
18
+ distribution => ' MetaFile-Both ' ,
19
+ release => ' MetaFile-Both-1.1 ' ,
20
+ url => ' http://cpancover.com/latest/MetaFile-Both-1.1 /index.html' ,
21
+ version => ' 1.1 ' ,
22
22
},
23
- ' Try-Tiny-0.27 ' => {
23
+ ' Pod-With-Generator-1 ' => {
24
24
criteria => {
25
25
branch => ' 78.95' ,
26
26
condition => ' 46.67' ,
27
27
statement => ' 95.06' ,
28
28
subroutine => ' 100.00' ,
29
29
total => ' 86.58' ,
30
30
},
31
- distribution => ' Try-Tiny ' ,
32
- release => ' Try-Tiny-0.27 ' ,
33
- url => ' http://cpancover.com/latest/Try-Tiny-0.27 /index.html' ,
34
- version => ' 0.27 ' ,
31
+ distribution => ' Pod-With-Generator ' ,
32
+ release => ' Pod-With-Generator-1 ' ,
33
+ url => ' http://cpancover.com/latest/Pod-With-Generator-1 /index.html' ,
34
+ version => ' 1 ' ,
35
35
},
36
36
);
37
37
Original file line number Diff line number Diff line change 1
1
{
2
- "Devel-GoFaster " : {
3
- "0.000 " : {
2
+ "MetaFile-Both " : {
3
+ "1.1 " : {
4
4
"coverage" : {
5
5
"total" : {
6
6
"branch" : " 12.50" ,
10
10
"total" : " 46.51"
11
11
}
12
12
}
13
- },
14
- "0.001" : {
15
- "coverage" : {
16
- "total" : {
17
- "branch" : " 12.50" ,
18
- "condition" : " 0.00" ,
19
- "statement" : " 61.90" ,
20
- "subroutine" : " 71.43" ,
21
- "total" : " 45.24"
22
- }
23
- }
24
13
}
25
14
},
26
- "Try-Tiny" : {
27
- "0.22" : {
28
- "coverage" : {
29
- "total" : {}
30
- }
31
- },
32
- "0.23" : {
33
- "coverage" : {
34
- "total" : {}
35
- }
36
- },
37
- "0.24" : {
38
- "coverage" : {
39
- "total" : {}
40
- }
41
- },
42
- "0.27" : {
15
+ "Pod-With-Generator" : {
16
+ "1" : {
43
17
"coverage" : {
44
18
"total" : {
45
19
"branch" : " 78.95" ,
50
24
"total" : " 86.58"
51
25
}
52
26
}
53
- },
54
- "0.28" : {
55
- "coverage" : {
56
- "total" : {
57
- "branch" : " 78.95" ,
58
- "condition" : " 46.67" ,
59
- "pod" : " 100.00" ,
60
- "statement" : " 95.06" ,
61
- "subroutine" : " 100.00" ,
62
- "total" : " 86.58"
63
- }
64
- }
65
- },
66
- "0.30" : {
67
- "coverage" : {
68
- "total" : {
69
- "branch" : " 78.95" ,
70
- "condition" : " 46.67" ,
71
- "pod" : " 100.00" ,
72
- "statement" : " 94.87" ,
73
- "subroutine" : " 100.00" ,
74
- "total" : " 86.30"
75
- }
76
- }
77
27
}
78
28
}
79
- }
29
+ }
You can’t perform that action at this time.
0 commit comments