Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/sentry/ownership/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def _path_to_regex(pattern: str) -> Pattern[str]:
SOFTWARE.
"""
regex = ""

# Special case backslash can match a backslash file or directory
if pattern[0] == "\\":
return re.compile(r"\\(?:\Z|/)")
Expand All @@ -277,10 +276,9 @@ def _path_to_regex(pattern: str) -> Pattern[str]:
matches_dir = pattern[-1] == "/"
if matches_dir:
pattern = pattern.rstrip("/")

# patterns ending with "/*" are special. They only match items directly in the directory
# not deeper
trailing_slash_star = pattern[-1] == "*" and len(pattern) > 1 and pattern[-2] == "/"
trailing_slash_star = pattern[-1] == "*" and pattern[-2] == "/" if len(pattern) > 1 else False

iterator = enumerate(pattern)

Expand Down
24 changes: 24 additions & 0 deletions tests/sentry/ownership/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,30 @@ def test_codeowners_match_backslash(path_details, expected):
_assert_matcher(Matcher("codeowners", "\\filename"), path_details, expected)


@pytest.mark.parametrize(
"path_details, expected",
[
([{"filename": "foo/"}, {"abs_path": "/usr/local/src/foo/"}], True),
(
[
{"filename": "/foo/subdir/"},
{"abs_path": "/usr/local/src/foo/subdir/"},
],
True,
),
(
[
{"filename": "config/subdir/test.py"},
{"abs_path": "/usr/local/src/config/subdir/test.py"},
],
True,
),
],
)
def test_codeowners_match_fowardslash(path_details, expected):
_assert_matcher(Matcher("codeowners", "/"), path_details, expected)


def test_parse_code_owners():
assert parse_code_owners(codeowners_fixture_data) == (
["@getsentry/frontend", "@getsentry/docs", "@getsentry/ecosystem"],
Expand Down