Skip to content

feat(codeowners): Support excluding subdirectories via no-owner rules#115322

Open
shashjar wants to merge 2 commits into
masterfrom
shashjar/support-excluding-subdirectories-in-codeowners
Open

feat(codeowners): Support excluding subdirectories via no-owner rules#115322
shashjar wants to merge 2 commits into
masterfrom
shashjar/support-excluding-subdirectories-in-codeowners

Conversation

@shashjar
Copy link
Copy Markdown
Member

@shashjar shashjar commented May 11, 2026

Resolves https://linear.app/getsentry/issue/ID-243/codeowners-doesnt-support-excluding-subdirectories.

Follow-up to #115391.

The CODEOWNERS spec (see below) allows for excluding ownership of subdirectories/specified paths by writing a rule with zero owners. With CODEOWNERS synced into Sentry, we are currently ignoring these no-owner rules. This PR implements that exclusion in ownership calculation.

# In this example, @octocat owns any file in the `/apps`
# directory in the root of your repository except for the `/apps/github`
# subdirectory, as its owners are left empty. Without an owner, changes
# to `apps/github` can be made with the approval of any user who has
# write access to the repository.
/apps/ @octocat
/apps/github

We will continue to skip lines where owners exist but aren't mapped into Sentry. Our "last match wins" semantics remain.

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 11, 2026

ID-243

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 11, 2026
event_tag = ~r"tags.[^:]+"

owners = _ owner+
owners = _ owner*
Copy link
Copy Markdown
Member Author

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

@shashjar shashjar requested a review from a team May 11, 2026 20:41
@shashjar shashjar marked this pull request as ready for review May 11, 2026 20:41
@shashjar shashjar requested review from a team as code owners May 11, 2026 20:41
@shashjar shashjar removed request for a team May 11, 2026 20:42
Comment thread src/sentry/issues/ownership/grammar.py
Copy link
Copy Markdown
Contributor

@cvxluo cvxluo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good overall. 2 questions:

  • will we support this exclusion syntax for issue owners as well?
  • will the frontend handle code owners with no owner properly?

rule_a = Rule(Matcher("codeowners", "/apps/"), [Owner("team", self.team.slug)])
rule_exclusion = Rule(Matcher("codeowners", "/apps/github"), [])
rule_c = Rule(
Matcher("codeowners", "/apps/github/special"), [Owner("team", self.team.slug)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very small nit: can we use a different team from the original to show that this is rule_c applying, rather than rule_a

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep good catch

([Actor(id=self.user.id, actor_type=ActorType.USER)], [issueowner_rule]),
)

def test_get_issue_owners_codeowners_exclusion_rule(self) -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, i'm a little confused on what this test is testing for. i understand the one above is that issue owners have priority over codeowners, but is this one also ttesting that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first one tests that an issue owner rule still applies even when a CODEOWNERS exclusion matches

the second one tests that the owner is correctly matched using only CODEOWNERS rules (one owner rule, one exclusion)

@shashjar shashjar marked this pull request as draft May 11, 2026 23:29
@shashjar
Copy link
Copy Markdown
Member Author

  1. Not planning to support this exclusion syntax for issue owners (at least for now). I believe the UI already prevents this, also added some backend validation for this specific to issue owners.

  2. Good catch - I think right now the ownership rules table does not support empty owners. Will make a frontend PR to match.

@shashjar shashjar marked this pull request as ready for review May 12, 2026 18:02
@shashjar shashjar requested a review from cvxluo May 12, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants