Skip to content

Commit b4b247f

Browse files
committed
add files_by_category end point
The existing interesting_files end point had a long list of files to include, with inconsistent rules for what file extensions and capitalization would be allowed. It also would just give the files back in a single list. The code for finding change logs partly reproduced this. Unify the logic for the files we search for, with consistent rules for file extensions, capitalization, and handling of special dists like "perl". Keep the different types of files categorized so that interesting_files can both filter the files it is querying for, and adding a new end point files_by_category to easily find the files of a specific type, like was previously possible for change logs. Install files and contributing docs are now listed on the front end, so this should make it easier for them to find the files.
1 parent d8e8962 commit b4b247f

File tree

4 files changed

+277
-217
lines changed

4 files changed

+277
-217
lines changed

lib/MetaCPAN/Document/File/Set.pm

Lines changed: 11 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ has query_file => (
1717
isa => 'MetaCPAN::Query::File',
1818
lazy => 1,
1919
builder => '_build_query_file',
20-
handles => [qw< dir interesting_files >],
20+
handles => [
21+
qw(
22+
dir
23+
interesting_files
24+
files_by_category
25+
)
26+
],
2127
);
2228

2329
sub _build_query_file {
@@ -654,75 +660,10 @@ sub autocomplete_suggester {
654660

655661
sub find_changes_files {
656662
my ( $self, $author, $release ) = @_;
657-
658-
# find the most likely file
659-
# TODO: should we do this when the release is indexed
660-
# and store the result as { 'changes_file' => $name }
661-
662-
my @candidates = qw(
663-
CHANGELOG
664-
ChangeLog
665-
Changelog
666-
ChangeLog.pm
667-
changelog.pm
668-
ChangeLog.pod
669-
CHANGES
670-
Changes
671-
CHANGES.md
672-
CHANGES.markdown
673-
CHANGES.pm
674-
Changes.pm
675-
CHANGES.pod
676-
Changes.pod
677-
NEWS
678-
);
679-
680-
# use $c->model b/c we can't let any filters apply here
681-
my $file = $self->raw->filter(
682-
{
683-
and => [
684-
{ term => { release => $release } },
685-
{ term => { author => $author } },
686-
{
687-
or => [
688-
689-
# if it's a perl release, get perldelta
690-
{
691-
and => [
692-
{ term => { distribution => 'perl' } },
693-
{
694-
term => {
695-
'name' => 'perldelta.pod'
696-
}
697-
},
698-
]
699-
},
700-
701-
# otherwise look for one of these candidates in the root
702-
{
703-
and => [
704-
{ term => { level => 0 } },
705-
{ term => { directory => 0 } },
706-
{
707-
or => [
708-
map { { term => { 'name' => $_ } } }
709-
@candidates
710-
]
711-
}
712-
]
713-
}
714-
],
715-
}
716-
]
717-
}
718-
)->size(1)
719-
720-
# HACK: Sort by level/desc to put pod/perldeta.pod first (if found)
721-
# otherwise sort root files by name and select the first.
722-
->sort( [ { level => 'desc' }, { name => 'asc' } ] )->first;
723-
724-
return unless is_hashref($file);
725-
return $file->{_source};
663+
my $result = $self->files_by_category( $author, $release, ['changelog'],
664+
{ fields => \1 } );
665+
my ($file) = @{ $result->{categories}{changelog} || [] };
666+
return $file;
726667
}
727668

728669
__PACKAGE__->meta->make_immutable;

0 commit comments

Comments
 (0)