|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use v5.36; |
| 4 | + |
| 5 | +use Getopt::Long; |
| 6 | +use Ref::Util qw< is_arrayref >; |
| 7 | + |
| 8 | +use MetaCPAN::Logger qw< :log :dlog >; |
| 9 | +use MetaCPAN::ES; |
| 10 | +use MetaCPAN::Contributor qw< |
| 11 | + get_cpan_author_contributors |
| 12 | + update_release_contirbutors |
| 13 | +>; |
| 14 | + |
| 15 | +# args |
| 16 | +my $all = 0; |
| 17 | +my ( $distribution, $release, $age ); |
| 18 | +GetOptions( |
| 19 | + "all" => \$all, |
| 20 | + "distribution=s" => \$distribution, |
| 21 | + "release=s" => \$release, |
| 22 | + "age=i" => \$age, |
| 23 | +); |
| 24 | + |
| 25 | +# Setup |
| 26 | +my $query |
| 27 | + = $all ? { match_all => {} } |
| 28 | + : $distribution |
| 29 | + ? { term => { distribution => $distribution } } |
| 30 | + : $release ? { |
| 31 | + bool => { |
| 32 | + must => [ |
| 33 | + { term => { author => get_author($release) } }, |
| 34 | + { term => { name => $release } }, |
| 35 | + ] |
| 36 | + } |
| 37 | + } |
| 38 | + : $age |
| 39 | + ? { range => { date => { gte => sprintf( 'now-%dd', $age ) } } } |
| 40 | + : die "Error: must provide 'all' or 'distribution' or 'release' or 'age'"; |
| 41 | + |
| 42 | +my $body = { query => $query }; |
| 43 | +my $timeout = $all ? '720m' : '5m'; |
| 44 | +my $fields = [qw< author distribution name >]; |
| 45 | + |
| 46 | +my $es_release = MetaCPAN::ES->new( type => "release" ); |
| 47 | +my $scroll = $es_release->scroll( |
| 48 | + body => $body, |
| 49 | + scroll => $timeout, |
| 50 | + fields => $fields, |
| 51 | +); |
| 52 | + |
| 53 | +while ( my $r = $scroll->next ) { |
| 54 | + my $contrib_data = get_cpan_author_contributors( |
| 55 | + $r->{fields}{author}[0], |
| 56 | + $r->{fields}{name}[0], |
| 57 | + $r->{fields}{distribution}[0], |
| 58 | + ); |
| 59 | + next unless is_arrayref($contrib_data); |
| 60 | + log_debug { 'adding release ' . $r->{fields}{name}[0] }; |
| 61 | + |
| 62 | + update_release_contirbutors( $_, $timeout ) for @$contrib_data; |
| 63 | +} |
| 64 | + |
| 65 | +### |
| 66 | + |
| 67 | +sub get_author ( $release ) { |
| 68 | + return unless $release; |
| 69 | + my $author = $release =~ s{/.*$}{}r; |
| 70 | + $author or die "Error: invalid 'release' argument (format: PAUSEID/DISTRIBUTION-VERSION)"; |
| 71 | + return $author; |
| 72 | +} |
| 73 | + |
| 74 | +1; |
| 75 | + |
| 76 | +__END__ |
| 77 | +
|
| 78 | +=head1 SYNOPSIS |
| 79 | +
|
| 80 | + # bin/contributor.pl --all |
| 81 | + # bin/contributor.pl --distribution Moose |
| 82 | + # bin/contributor.pl --release ETHER/Moose-2.1806 |
| 83 | +
|
| 84 | +=head1 DESCRIPTION |
| 85 | +
|
| 86 | +Update the list of contributors (CPAN authors only) of all/matching |
| 87 | +releases in the 'contributor' type (index). |
| 88 | +
|
| 89 | +=cut |
0 commit comments