-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(codeowners): Support excluding subdirectories via no-owner rules #115322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shashjar
merged 2 commits into
master
from
shashjar/support-excluding-subdirectories-in-codeowners
May 12, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1299,3 +1299,132 @@ def test_empty_bad_owners(self) -> None: | |
| project = self.create_project() | ||
| messages = get_invalid_owner_details([], project.id) | ||
| assert messages == [] | ||
|
|
||
|
|
||
| def test_parse_rules_with_exclusion_rule() -> None: | ||
| rules = parse_rules("codeowners:/apps/\ncodeowners:/apps/github\n") | ||
| assert rules == [ | ||
| Rule(Matcher("codeowners", "/apps/"), []), | ||
| Rule(Matcher("codeowners", "/apps/github"), []), | ||
| ] | ||
|
|
||
|
|
||
| def test_parse_rules_exclusion_rule_mixed() -> None: | ||
| rules = parse_rules("codeowners:/apps/ [email protected]\ncodeowners:/apps/github\n") | ||
| assert rules == [ | ||
| Rule(Matcher("codeowners", "/apps/"), [Owner("user", "[email protected]")]), | ||
| Rule(Matcher("codeowners", "/apps/github"), []), | ||
| ] | ||
|
|
||
|
|
||
| def test_dump_load_schema_exclusion_rule() -> None: | ||
| rule_with_owner = Rule(Matcher("codeowners", "/apps/"), [Owner("user", "[email protected]")]) | ||
| rule_exclusion = Rule(Matcher("codeowners", "/apps/github"), []) | ||
|
|
||
| schema = dump_schema([rule_with_owner, rule_exclusion]) | ||
| assert schema == { | ||
| "$version": 1, | ||
| "rules": [ | ||
| { | ||
| "matcher": {"type": "codeowners", "pattern": "/apps/"}, | ||
| "owners": [{"type": "user", "identifier": "[email protected]"}], | ||
| }, | ||
| { | ||
| "matcher": {"type": "codeowners", "pattern": "/apps/github"}, | ||
| "owners": [], | ||
| }, | ||
| ], | ||
| } | ||
| assert load_schema(schema) == [rule_with_owner, rule_exclusion] | ||
|
|
||
|
|
||
| def test_str_exclusion_rule() -> None: | ||
| assert str(Rule(Matcher("codeowners", "/apps/github"), [])) == "codeowners:/apps/github" | ||
|
|
||
|
|
||
| def test_convert_schema_to_rules_text_exclusion_rule() -> None: | ||
| assert ( | ||
| convert_schema_to_rules_text( | ||
| { | ||
| "$version": 1, | ||
| "rules": [ | ||
| { | ||
| "matcher": {"type": "codeowners", "pattern": "/apps/"}, | ||
| "owners": [{"type": "user", "identifier": "[email protected]"}], | ||
| }, | ||
| { | ||
| "matcher": {"type": "codeowners", "pattern": "/apps/github"}, | ||
| "owners": [], | ||
| }, | ||
| ], | ||
| } | ||
| ) | ||
| == "codeowners:/apps/ [email protected]\ncodeowners:/apps/github\n" | ||
| ) | ||
|
|
||
|
|
||
| def test_convert_codeowners_syntax_exclusion_rule() -> None: | ||
| code_mapping = type("", (), {})() | ||
| code_mapping.stack_root = "" | ||
| code_mapping.source_root = "" | ||
|
|
||
| codeowners = "/apps/ @octocat\n/apps/github\n" | ||
| result = convert_codeowners_syntax( | ||
| codeowners, | ||
| {"@octocat": "[email protected]"}, | ||
| code_mapping, | ||
| ) | ||
| assert "codeowners:/apps/ [email protected]\n" in result | ||
| assert "codeowners:/apps/github\n" in result | ||
|
|
||
|
|
||
| def test_convert_codeowners_syntax_exclusion_with_comment() -> None: | ||
| code_mapping = type("", (), {})() | ||
| code_mapping.stack_root = "" | ||
| code_mapping.source_root = "" | ||
|
|
||
| codeowners = "/apps/ @octocat\n/apps/github # Skip\n" | ||
| result = convert_codeowners_syntax( | ||
| codeowners, | ||
| {"@octocat": "[email protected]"}, | ||
| code_mapping, | ||
| ) | ||
| assert "codeowners:/apps/ [email protected]\n" in result | ||
| assert "codeowners:/apps/github\n" in result | ||
|
|
||
|
|
||
| def test_convert_codeowners_syntax_unmapped_owner_not_exclusion() -> None: | ||
| code_mapping = type("", (), {})() | ||
| code_mapping.stack_root = "" | ||
| code_mapping.source_root = "" | ||
|
|
||
| codeowners = "/apps/ @unknown-user\n" | ||
| result = convert_codeowners_syntax( | ||
| codeowners, | ||
| {}, | ||
| code_mapping, | ||
| ) | ||
| assert "codeowners:/apps/" not in result | ||
|
|
||
|
|
||
| def test_convert_codeowners_syntax_exclusion_with_stack_root() -> None: | ||
| code_mapping = type("", (), {})() | ||
| code_mapping.stack_root = "webpack://static/" | ||
| code_mapping.source_root = "" | ||
|
|
||
| codeowners = "/apps/ @octocat\n/apps/github\n" | ||
| result = convert_codeowners_syntax( | ||
| codeowners, | ||
| {"@octocat": "[email protected]"}, | ||
| code_mapping, | ||
| ) | ||
| assert "codeowners:webpack://static/apps/ [email protected]\n" in result | ||
| assert "codeowners:webpack://static/apps/github\n" in result | ||
|
|
||
|
|
||
| def test_parse_code_owners_exclusion_rule() -> None: | ||
| codeowners = "/apps/ @getsentry/frontend\n/apps/github\n" | ||
| teams, usernames, emails = parse_code_owners(codeowners) | ||
| assert teams == ["@getsentry/frontend"] | ||
| assert usernames == [] | ||
| assert emails == [] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One or more owners —> zero or more owners