Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
contributors endpoint: make release based (takes author/version)
  • Loading branch information
mickeyn committed May 12, 2017
1 parent 896370a commit f86e85e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
29 changes: 17 additions & 12 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -374,14 +374,14 @@ sub find_github_based {
}

sub get_contributors {
my ( $self, $dist ) = @_;
my ( $self, $author_name, $release_name ) = @_;

my $query = +{
query => {
bool => {
must => [
{ term => { distribution => $dist } },
{ term => { status => 'latest' } },
{ term => { name => $release_name } },
{ term => { author => $author_name } },
],
},
}
Expand All @@ -393,7 +393,7 @@ sub get_contributors {
body => {
query => $query,
size => 999,
_source => [qw< author metadata.author metadata.x_contributors >],
_source => [qw< metadata.author metadata.x_contributors >],
}
);

Expand All @@ -416,21 +416,25 @@ sub get_contributors {
my $author = $self->es->get(
index => $self->index->name,
type => 'author',
id => $release->{author},
id => $author_name,
);

my $author_email = $author->{_source}{email};
my $author_info = {
my $author_email = $author->{_source}{email};
my $author_gravatar_url = $author->{_source}{gravatar_url};

my $author_info = {
email => [
lc "$release->{author}\@cpan.org",
lc "$author_name\@cpan.org",
(
Ref::Util::is_arrayref($author_email)
? @{$author_email}
Ref::Util::is_arrayref($author_email) ? @{$author_email}
: $author_email
),
],
name => $author->{_source}{name},
gravatar_url => $author->{_source}{gravatar_url},
name => $author_name,
(
$author_gravatar_url ? ( gravatar_url => $author_gravatar_url )
: ()
),
};
my %seen = map { $_ => $author_info }
( @{ $author_info->{email} }, $author_info->{name}, );
Expand Down Expand Up @@ -498,6 +502,7 @@ sub get_contributors {
my %id2url = map { $_->{_source}{pauseid} => $_->{_source}{gravatar_url} }
@{ $contrib_authors->{hits}{hits} };
for my $contrib (@contribs) {
next unless $contrib->{pauseid};
$contrib->{gravatar_url} = $id2url{ $contrib->{pauseid} }
if exists $id2url{ $contrib->{pauseid} };
}
Expand Down
6 changes: 3 additions & 3 deletions lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -52,9 +52,9 @@ sub get : Path('') : Args(2) {
['The requested field(s) could not be found'] );
}

sub contributors : Path('contributors') : Args(1) {
my ( $self, $c, $name ) = @_;
my $data = $self->model($c)->raw->get_contributors($name);
sub contributors : Path('contributors') : Args(2) {
my ( $self, $c, $author, $release ) = @_;
my $data = $self->model($c)->raw->get_contributors( $author, $release );
$c->stash($data);
}

Expand Down

0 comments on commit f86e85e

Please sign in to comment.