Skip to content

Commit eb48fd3

Browse files
committed
Added contributor script
1 parent 8793123 commit eb48fd3

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

bin/contributor.pl

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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

lib/MetaCPAN/Contributor.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ use MetaCPAN::Ingest qw<
1414

1515
use Sub::Exporter -setup => {
1616
exports => [ qw<
17+
get_cpan_author_contributors
1718
update_release_contirbutors
1819
> ]
1920
};
2021

21-
sub _get_cpan_author_contributors ( $author, $release, $distribution ) {
22+
sub get_cpan_author_contributors ( $author, $release, $distribution ) {
2223
my @ret;
2324

2425
my $data;
@@ -49,7 +50,7 @@ sub _get_cpan_author_contributors ( $author, $release, $distribution ) {
4950
}
5051

5152
sub update_release_contirbutors ( $document, $timeout = "5m" ) {
52-
my $data = _get_cpan_author_contributors(
53+
my $data = get_cpan_author_contributors(
5354
@{$document}{qw< author name distribution >} );
5455
return unless $data and is_arrayref($data);
5556

lib/MetaCPAN/ES.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ sub scroll ( $self, %args ) {
9696
body => ( $args{body} // { query => { match_all => {} } } ),
9797
search_type => 'scan',
9898
scroll => ( $args{scroll} // '30m' ),
99+
( $args{fields} ? ( fields => $args{fields} ) : () ),
99100
);
100101
}
101102

0 commit comments

Comments
 (0)