File tree Expand file tree Collapse file tree 3 files changed +94
-0
lines changed
Expand file tree Collapse file tree 3 files changed +94
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ has query_release => (
2020 author_status
2121 by_author
2222 by_author_and_name
23+ by_author_and_names
2324 get_contributors
2425 get_files
2526 latest_by_author
Original file line number Diff line number Diff line change @@ -357,6 +357,57 @@ sub by_author_and_name {
357357 };
358358}
359359
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+ +{
371+ query => {
372+ bool => {
373+ must => [
374+ {
375+ term => {
376+ author => uc ( $_ -> {author } )
377+ }
378+ },
379+ { term => { ' name' => $_ -> {name } } },
380+ ]
381+ }
382+ }
383+ }
384+ } @$releases
385+ ]
386+ }
387+ }
388+ };
389+
390+ my $ret = $self -> es-> search(
391+ index => $self -> index_name,
392+ type => ' release' ,
393+ body => $body ,
394+ );
395+ return unless $ret -> {hits }{total };
396+
397+ my @releases ;
398+ for my $hit ( @{ $ret -> {hits }{hits } } ) {
399+ my $src = $hit -> {_source };
400+ single_valued_arrayref_to_scalar($src );
401+ push @releases , $src ;
402+ }
403+
404+ return {
405+ took => $ret -> {took },
406+ total => $ret -> {hits }{total },
407+ releases => \@releases ,
408+ };
409+ }
410+
360411sub by_author {
361412 my ( $self , $pauseid , $size ) = @_ ;
362413 $size //= 1000;
Original file line number Diff line number Diff line change @@ -65,4 +65,46 @@ sub all : Chained('index') : PathPart('') : Args(0) {
6565 $c -> detach(' not_found' );
6666}
6767
68+ sub by_releases : Path(' by_releases' ) : Args(0) {
69+ my ( $self , $c ) = @_ ;
70+
71+ my @releases = map {
72+ my @o = split ( ' /' , $_ , 2 );
73+ @o == 2 ? { author => $o [0], name => $o [1] } : ();
74+ } @{ $c -> read_param(" release" ) };
75+
76+ unless (@releases ) {
77+ $c -> stash( { changes => [] } );
78+ return ;
79+ }
80+
81+ my $ret = $c -> model(' CPAN::Release' )-> by_author_and_names( \@releases );
82+
83+ my @changes ;
84+ for my $release ( @{ $ret -> {releases } } ) {
85+ my ( $author , $name , $path )
86+ = @{$release }{qw( author name changes_file) };
87+ my $source = $c -> model(' Source' )-> path( $author , $name , $path )
88+ or next ;
89+
90+ my $content = try {
91+ Encode::decode(
92+ ' UTF-8' ,
93+ ( scalar $source -> slurp ),
94+ Encode::FB_CROAK | Encode::LEAVE_SRC
95+ );
96+ } or next ;
97+
98+ push @changes ,
99+ {
100+ author => $author ,
101+ release => $name ,
102+ changes_text => $content ,
103+ changes_file => $path ,
104+ };
105+ }
106+
107+ $c -> stash( { changes => \@changes } );
108+ }
109+
681101;
You can’t perform that action at this time.
0 commit comments