Skip to content

Commit 00246f4

Browse files
authored
Merge pull request #814 from metacpan/haarg/interesting-file-locations
improve choices for interesting files
2 parents 8848e7f + 0fa860d commit 00246f4

File tree

2 files changed

+101
-27
lines changed

2 files changed

+101
-27
lines changed

lib/MetaCPAN/Model/Release.pm

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,27 +267,54 @@ sub set_main_module {
267267

268268
}
269269

270-
sub get_changes_file {
271-
my $self = shift;
272-
my @files = @{ $_[0] };
273-
my @changes_files = qw(
274-
Changelog
275-
ChangeLog
276-
CHANGELOG
277-
Changes
278-
CHANGES
279-
NEWS
270+
my @changes_files = qw(
271+
CHANGELOG
272+
ChangeLog
273+
Changelog
274+
CHANGES
275+
Changes
276+
NEWS
277+
);
278+
my @exclude_dirs = qw(
279+
corpus
280+
fatlib
281+
inc
282+
local
283+
perl5
284+
share
285+
t
286+
xt
287+
);
288+
289+
# this should match the same set of files as MetaCPAN::Query::File->interesting_files
290+
my ($changes_match) = map qr/^(?:$_)$/, join '|',
291+
( map quotemeta, @changes_files ),
292+
(
293+
"(?:(?!"
294+
. join( '|', map "$_/", @exclude_dirs )
295+
. ").*/)?(?:"
296+
. join(
297+
'|', map quotemeta, map +( "$_.pm", "$_.pod" ), @changes_files
298+
)
299+
. ')'
280300
);
281301

302+
sub get_changes_file {
303+
my $self = shift;
304+
my @files = @{ $_[0] };
282305
if ( $files[0]->distribution eq 'perl' ) {
283306
foreach my $file (@files) {
284307
if ( $file->name eq 'perldelta.pod' ) {
285308
return $file->path;
286309
}
287310
}
288311
}
312+
313+
# prioritize files in the top level but otherwise alphabetical
314+
@files = sort { $a->level <=> $b->level || $a->path cmp $b->path } @files;
315+
289316
foreach my $file (@files) {
290-
return $file->path if grep { $_ eq $file->path } @changes_files;
317+
return $file->path if $file->path =~ $changes_match;
291318
}
292319
}
293320

lib/MetaCPAN/Query/File.pm

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,49 +55,61 @@ sub interesting_files {
5555
{ term => { release => $release } },
5656
{ term => { author => $author } },
5757
{ term => { directory => \0 } },
58-
{ not => { prefix => { 'path' => 'xt/' } } },
58+
{ not => { prefix => { 'path' => 'corpus/' } } },
59+
{ not => { prefix => { 'path' => 'fatlib/' } } },
60+
{ not => { prefix => { 'path' => 'inc/' } } },
61+
{ not => { prefix => { 'path' => 'local/' } } },
62+
{ not => { prefix => { 'path' => 'perl5/' } } },
63+
{ not => { prefix => { 'path' => 'share/' } } },
5964
{ not => { prefix => { 'path' => 't/' } } },
65+
{ not => { prefix => { 'path' => 'xt/' } } },
6066
{
6167
bool => {
6268
should => [
6369
{
6470
bool => {
6571
must => [
72+
{ term => { level => 0 } },
6673
{
6774
terms => {
6875
name => [
6976
qw(
77+
alienfile
7078
AUTHORS
7179
Build.PL
7280
CHANGELOG
81+
ChangeLog
82+
Changelog
7383
CHANGES
84+
Changes
7485
CONTRIBUTING
7586
CONTRIBUTING.md
76-
CONTRIBUTING.pod
77-
Contributing.pm
78-
Contributing.pod
87+
Contributing
7988
COPYING
89+
Copying
8090
COPYRIGHT
91+
cpanfile
8192
CREDITS
82-
ChangeLog
83-
Changelog
84-
Changes
85-
Copying
93+
DEVELOPMENT
94+
DEVELOPMENT.md
95+
Development
96+
Development.md
97+
dist.ini
8698
FAQ
99+
FAQ.md
87100
HACKING
88101
HACKING.md
89-
HACKING.pod
90-
Hacking.pm
91-
Hacking.pod
92102
Hacking
103+
Hacking.md
93104
INSTALL
94105
INSTALL.md
95106
LICENCE
96107
LICENSE
97108
MANIFEST
109+
Makefile.PL
98110
META.json
99111
META.yml
100-
Makefile.PL
112+
minil.toml
101113
NEWS
102114
README
103115
README.markdown
@@ -106,12 +118,47 @@ sub interesting_files {
106118
README.mkdn
107119
THANKS
108120
TODO
121+
TODO.md
109122
ToDo
123+
ToDo.md
110124
Todo
111-
cpanfile
112-
alienfile
113-
dist.ini
114-
minil.toml
125+
Todo.md
126+
)
127+
]
128+
}
129+
}
130+
]
131+
}
132+
},
133+
{
134+
bool => {
135+
must => [
136+
{
137+
terms => {
138+
name => [
139+
qw(
140+
CONTRIBUTING.pm
141+
CONTRIBUTING.pod
142+
Contributing.pm
143+
Contributing.pod
144+
ChangeLog.pm
145+
ChangeLog.pod
146+
Changelog.pm
147+
Changelog.pod
148+
CHANGES.pm
149+
CHANGES.pod
150+
Changes.pm
151+
Changes.pod
152+
HACKING.pm
153+
HACKING.pod
154+
Hacking.pm
155+
Hacking.pod
156+
TODO.pm
157+
TODO.pod
158+
ToDo.pm
159+
ToDo.pod
160+
Todo.pm
161+
Todo.pod
115162
)
116163
]
117164
}

0 commit comments

Comments
 (0)