Skip to content

Commit bb5c574

Browse files
committed
scripts: get_maintainer: file group pattern inherit top area patterns
File groups inherit file patterns from their parent area. A file will only match a file group if it first matches the parent area's patterns, and then also matches the file group's own patterns. This allows file groups to further filter and subdivide files that are already covered by the area. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
1 parent 6e78732 commit bb5c574

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

MAINTAINERS.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
# A list of groups of files that are treated as a single unit.
6565
# This is useful for areas where different collaborators are responsible for
6666
# different parts of the area.
67+
#
68+
# File groups inherit file patterns from their parent area. A file will only
69+
# match a file group if it first matches the parent area's patterns, and then
70+
# also matches the file group's own patterns. This allows file groups to
71+
# further filter and subdivide files that are already covered by the area.#
72+
#
6773
# Each group should have the following structure:
6874
# - name: <group name>
6975
# collaborators:

scripts/ci/set_assignees.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def process_pr(gh, maintainer_file, number):
235235
# areas where assignment happens if only said areas are affected
236236
meta_areas = ['Release Notes', 'Documentation', 'Samples', 'Tests']
237237

238-
collab_per_path = []
238+
collab_per_path = set()
239239
additional_reviews = set()
240240
for changed_file in fn:
241241
num_files += 1
@@ -248,7 +248,7 @@ def process_pr(gh, maintainer_file, number):
248248
continue
249249
parsed_areas = process_manifest(old_manifest_file=args.updated_manifest)
250250
for _area in parsed_areas:
251-
collab_per_path.extend(_area.get_collaborators_for_path(changed_file.filename))
251+
collab_per_path.update(_area.get_collaborators_for_path(changed_file.filename))
252252
area_match = maintainer_file.name2areas(_area)
253253
if area_match:
254254
areas.extend(area_match)
@@ -271,9 +271,9 @@ def process_pr(gh, maintainer_file, number):
271271
else:
272272
areas = maintainer_file.path2areas(changed_file.filename)
273273
for _area in areas:
274-
collab_per_path.extend(_area.get_collaborators_for_path(changed_file.filename))
274+
collab_per_path.update(_area.get_collaborators_for_path(changed_file.filename))
275275

276-
log(f"areas for {changed_file}: {areas}")
276+
log(f" areas: {areas}")
277277

278278
if not areas:
279279
continue
@@ -302,7 +302,7 @@ def process_pr(gh, maintainer_file, number):
302302
is_instance = True
303303

304304
for _area in sorted_areas:
305-
collab_per_path.extend(_area.get_collaborators_for_path(changed_file.filename))
305+
collab_per_path.update(_area.get_collaborators_for_path(changed_file.filename))
306306

307307
area_counter = dict(sorted(area_counter.items(), key=lambda item: item[1], reverse=True))
308308
log(f"Area matches: {area_counter}")

scripts/get_maintainer.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ def __init__(self, filename=None):
236236
_get_match_fn(group_dict.get("files-exclude"),
237237
group_dict.get("files-regex-exclude"))
238238

239+
# Store reference to parent area for inheritance
240+
file_group._parent_area = area
241+
239242
area.file_groups.append(file_group)
240243

241244
# area._match_fn(path) tests if the path matches files and/or
@@ -470,6 +473,11 @@ class FileGroup:
470473
"""
471474
Represents a file group within an area in MAINTAINERS.yml.
472475
476+
File groups inherit file patterns from their parent area. A file will only
477+
match a file group if it first matches the parent area's patterns, and then
478+
also matches the file group's own patterns. This allows file groups to
479+
further filter and subdivide files that are already covered by the area.
480+
473481
These attributes are available:
474482
475483
name:
@@ -481,8 +489,25 @@ class FileGroup:
481489
collaborators:
482490
List of collaborators specific to this file group
483491
"""
492+
def _parent_area_contains(self, path):
493+
"""
494+
Returns True if the parent area contains 'path', False otherwise.
495+
"""
496+
return (self._parent_area._match_fn and
497+
self._parent_area._match_fn(path) and not
498+
(self._parent_area._exclude_match_fn and
499+
self._parent_area._exclude_match_fn(path)))
500+
484501
def _contains(self, path):
485502
# Returns True if the file group contains 'path', and False otherwise
503+
# File groups inherit from their parent area - a file must match the
504+
# parent area's patterns first, then the file group's patterns
505+
506+
# First check if the path matches the parent area's patterns
507+
if not self._parent_area_contains(path):
508+
return False
509+
510+
# Then check if it matches this file group's patterns
486511
return self._match_fn and self._match_fn(path) and not \
487512
(self._exclude_match_fn and self._exclude_match_fn(path))
488513

0 commit comments

Comments
 (0)