File tree Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ has query_release => (
20
20
author_status
21
21
by_author
22
22
by_author_and_name
23
+ by_author_and_names
23
24
get_contributors
24
25
get_files
25
26
latest_by_author
Original file line number Diff line number Diff line change @@ -357,6 +357,51 @@ sub by_author_and_name {
357
357
};
358
358
}
359
359
360
+ sub by_author_and_names {
361
+ my ( $self , $releases ) = @_ ;
362
+
363
+ # $releases: ArrayRef[ Dict[ author => Str, name => Str ] ]
364
+
365
+ my $body = {
366
+ query => {
367
+ bool => {
368
+ should => [
369
+ map { +{
370
+ query => {
371
+ bool => {
372
+ must => [
373
+ { term => { author => uc ($_ -> {author }) } },
374
+ { term => { ' name' => $_ -> {name } } },
375
+ ]
376
+ }
377
+ }
378
+ } } @$releases
379
+ ]
380
+ }
381
+ }
382
+ };
383
+
384
+ my $ret = $self -> es-> search(
385
+ index => $self -> index_name,
386
+ type => ' release' ,
387
+ body => $body ,
388
+ );
389
+ return unless $ret -> {hits }{total };
390
+
391
+ my @releases ;
392
+ for my $hit (@{ $ret -> {hits }{hits } }) {
393
+ my $src = $hit -> {_source };
394
+ single_valued_arrayref_to_scalar($src );
395
+ push @releases , $src ;
396
+ }
397
+
398
+ return {
399
+ took => $ret -> {took },
400
+ total => $ret -> {hits }{total },
401
+ releases => \@releases ,
402
+ };
403
+ }
404
+
360
405
sub by_author {
361
406
my ( $self , $pauseid , $size ) = @_ ;
362
407
$size //= 1000;
Original file line number Diff line number Diff line change @@ -65,4 +65,38 @@ sub all : Chained('index') : PathPart('') : Args(0) {
65
65
$c -> detach(' not_found' );
66
66
}
67
67
68
+ sub by_releases : Path(' by_releases' ) : Args(0) {
69
+ my ( $self , $c ) = @_ ;
70
+
71
+ # ArrayRef[ Dict[ author => Str, name => Str ] ]
72
+ my $arg = $c -> read_param(" releases" );
73
+ my $ret = $c -> model(' CPAN::Release' )-> by_author_and_names( $arg );
74
+
75
+ my @changes ;
76
+ for my $release (@{$ret -> {releases }}) {
77
+ my ($author , $name , $path ) = @{$release }{ qw( author name changes_file) };
78
+ my $source = $c -> model(' Source' )-> path( $author , $name , $path ) // ' ' ;
79
+
80
+ my $content ;
81
+ try {
82
+ local $/ ;
83
+ $content = Encode::decode(
84
+ ' UTF-8' ,
85
+ (scalar $source -> openr-> getline),
86
+ Encode::FB_CROAK | Encode::LEAVE_SRC
87
+ );
88
+ } catch {
89
+ $content = undef ;
90
+ };
91
+
92
+ push @changes , {
93
+ author => $author ,
94
+ release => $name ,
95
+ changes_text => $content ,
96
+ }
97
+ }
98
+
99
+ $c -> stash({ changes => \@changes });
100
+ }
101
+
68
102
1;
You can’t perform that action at this time.
0 commit comments