Skip to content

Commit

Permalink
Merge pull request #52 from metacpan/mickey/contributor
Browse files Browse the repository at this point in the history
get_contributors: follow api changes
  • Loading branch information
mickeyn authored Nov 5, 2024
2 parents 97bec19 + f73e6c1 commit 4d7b9a4
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/MetaCPAN/Contributor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ sub get_contributors ( $author_name, $release_name ) {
$dupe ? () : $info;
} ( @$authors, @$contribs );

my %want_email;
for my $contrib (@contribs) {

# heuristic to autofill pause accounts
Expand All @@ -189,20 +190,26 @@ sub get_contributors ( $author_name, $release_name ) {

}

# check if contributor's email points to a registered author
if ( !$contrib->{pauseid} ) {
for my $email ( @{ $contrib->{email} } ) {
my $check_author = $es->search(
type => 'author',
body => {
query => { term => { email => $email } },
size => 10,
}
);

if ( $check_author->{hits}{total} ) {
$contrib->{pauseid}
= uc $check_author->{hits}{hits}[0]{_source}{pauseid};
push @{ $want_email{$_} }, $contrib for @{ $contrib->{email} };
}

if (%want_email) {
my $check_author = $es->search(
type => 'author',
body => {
query => { term => { email => [ sort keys %want_email ] } },
_source => [ 'email', 'pauseid' ],
size => 10,
}
);

for my $author ( @{ $check_author->{hits}{hits} } ) {
my $emails = $author->{_source}{email};
$emails = [$emails] if !ref $emails;
my $pauseid = uc $author->{_source}{pauseid};
for my $email (@$emails) {
for my $contrib ( @{ $want_email{$email} } ) {
$contrib->{pauseid} = $pauseid;
}
}
}
Expand Down

0 comments on commit 4d7b9a4

Please sign in to comment.