diff --git a/.github/scripts/assign_reviewers.py b/.github/scripts/assign_reviewers.py index 1b8fd9b4be..548ea3cb49 100644 --- a/.github/scripts/assign_reviewers.py +++ b/.github/scripts/assign_reviewers.py @@ -22,12 +22,16 @@ from collections import Counter from pathlib import Path def pattern_to_regex(pattern): - start_anchor = pattern.startswith("/") - pattern = re.escape(pattern) + if pattern.startswith("/"): + start_anchor = True + pattern = re.escape(pattern[1:]) + else: + start_anchor = False + pattern = re.escape(pattern) # Replace `*` with "any number of non-slash characters" pattern = pattern.replace(r"\*", "[^/]*") if start_anchor: - pattern = "^" + pattern + pattern = r"^\/?" + pattern # Allow an optional leading slash after the start of the string return pattern def get_file_owners(file_path, codeowners_lines):