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>
This commit is contained in:
Anas Nashif
2025-11-07 05:24:20 -05:00
parent 19cb7f031b
commit c55d2eafff
3 changed files with 36 additions and 5 deletions

View File

@@ -64,6 +64,12 @@
# A list of groups of files that are treated as a single unit.
# This is useful for areas where different collaborators are responsible for
# different parts of the area.
#
# 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.
#
# Each group should have the following structure:
# - name: <group name>
# collaborators:

View File

@@ -235,7 +235,7 @@ def process_pr(gh, maintainer_file, number):
# areas where assignment happens if only said areas are affected
meta_areas = ['Release Notes', 'Documentation', 'Samples', 'Tests']
collab_per_path = []
collab_per_path = set()
additional_reviews = set()
for changed_file in fn:
num_files += 1
@@ -248,7 +248,7 @@ def process_pr(gh, maintainer_file, number):
continue
parsed_areas = process_manifest(old_manifest_file=args.updated_manifest)
for _area in parsed_areas:
collab_per_path.extend(_area.get_collaborators_for_path(changed_file.filename))
collab_per_path.update(_area.get_collaborators_for_path(changed_file.filename))
area_match = maintainer_file.name2areas(_area)
if area_match:
areas.extend(area_match)
@@ -271,9 +271,9 @@ def process_pr(gh, maintainer_file, number):
else:
areas = maintainer_file.path2areas(changed_file.filename)
for _area in areas:
collab_per_path.extend(_area.get_collaborators_for_path(changed_file.filename))
collab_per_path.update(_area.get_collaborators_for_path(changed_file.filename))
log(f"areas for {changed_file}: {areas}")
log(f" areas: {areas}")
if not areas:
continue
@@ -302,7 +302,7 @@ def process_pr(gh, maintainer_file, number):
is_instance = True
for _area in sorted_areas:
collab_per_path.extend(_area.get_collaborators_for_path(changed_file.filename))
collab_per_path.update(_area.get_collaborators_for_path(changed_file.filename))
area_counter = dict(sorted(area_counter.items(), key=lambda item: item[1], reverse=True))
log(f"Area matches: {area_counter}")

View File

@@ -236,6 +236,9 @@ class Maintainers:
_get_match_fn(group_dict.get("files-exclude"),
group_dict.get("files-regex-exclude"))
# Store reference to parent area for inheritance
file_group._parent_area = area
area.file_groups.append(file_group)
# area._match_fn(path) tests if the path matches files and/or
@@ -470,6 +473,11 @@ class FileGroup:
"""
Represents a file group within an area in MAINTAINERS.yml.
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.
These attributes are available:
name:
@@ -481,8 +489,25 @@ class FileGroup:
collaborators:
List of collaborators specific to this file group
"""
def _parent_area_contains(self, path):
"""
Returns True if the parent area contains 'path', False otherwise.
"""
return (self._parent_area._match_fn and
self._parent_area._match_fn(path) and not
(self._parent_area._exclude_match_fn and
self._parent_area._exclude_match_fn(path)))
def _contains(self, path):
# Returns True if the file group contains 'path', and False otherwise
# File groups inherit from their parent area - a file must match the
# parent area's patterns first, then the file group's patterns
# First check if the path matches the parent area's patterns
if not self._parent_area_contains(path):
return False
# Then check if it matches this file group's patterns
return self._match_fn and self._match_fn(path) and not \
(self._exclude_match_fn and self._exclude_match_fn(path))