Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(devex): match CODEOWNERS dir patterns at the directory boundary (#62356)

Robbiefbc79944be5c
diff --git a/.github/scripts/assign-reviewers.js b/.github/scripts/assign-reviewers.js
index fb9966a15237..04a13bae04c2 100644
--- a/.github/scripts/assign-reviewers.js
+++ b/.github/scripts/assign-reviewers.js
@@ -154,8 +154,12 @@ function globToRegex(pattern) {
.replace(/\*/g, '[^/]*')
.replace(/__DOUBLESTAR__/g, '.*')
+ // A trailing-slash pattern is a directory: keep the slash so it matches only
+ // files inside the directory, not sibling paths sharing the name as a prefix
+ // (e.g. `models/ai/` must not match `models/ai_events/`). Mirrors GitHub's
+ // own CODEOWNERS semantics, where `dir/` is a directory boundary.
if (pattern.endsWith('/')) {
- regex = regex.slice(0, -1) + '.*'
+ regex = regex + '.*'
}
return new RegExp(`^${regex}$`)
diff --git a/.github/scripts/assign-reviewers.test.js b/.github/scripts/assign-reviewers.test.js
index 761d0afdc81d..31c6f5a786e4 100644
--- a/.github/scripts/assign-reviewers.test.js
+++ b/.github/scripts/assign-reviewers.test.js
@@ -6,6 +6,7 @@ const {
isSubstantive,
classifyOwners,
buildReviewerComment,
+ fileMatchesPattern,
} = require('./assign-reviewers')
const file = (filename, additions = 0, deletions = 0) => ({
@@ -34,6 +35,29 @@ describe('assign-reviewers', () => {
})
})
+ describe('fileMatchesPattern', () => {
+ test.each([
+ // a trailing slash is a directory boundary, not a name prefix
+ ['posthog/models/ai/utils.py', 'posthog/models/ai/', true],
+ ['posthog/models/ai/sub/deep.py', 'posthog/models/ai/', true],
+ ['posthog/models/ai_events/event.py', 'posthog/models/ai/', false],
+ ['posthog/models/person/util.py', 'posthog/models/person/', true],
+ ['posthog/models/person_overrides/x.py', 'posthog/models/person/', false],
+ ['posthog/models/personal_api_key.py', 'posthog/models/person/', false],
+ // /** is bounded to the directory, same as a trailing slash
+ ['posthog/models/ai/utils.py', 'posthog/models/ai/**', true],
+ ['posthog/models/ai_events/event.py', 'posthog/models/ai/**', false],
+ // a single star stays within one path segment
+ ['posthog/dags/sessions.py', 'posthog/dags/*.py', true],
+ ['posthog/dags/sub/sessions.py', 'posthog/dags/*.py', false],
+ // exact-file patterns match only that file
+ ['posthog/api/person.py', 'posthog/api/person.py', true],
+ ['posthog/api/person_other.py', 'posthog/api/person.py', false],
+ ])('%s vs %s', (filename, pattern, expected) => {
+ expect(fileMatchesPattern(filename, pattern)).toBe(expected)
+ })
+ })
+
describe('classifyOwner', () => {
test.each([
['@PostHog/team-surveys', { type: 'team', name: 'team-surveys', owner: '@PostHog/team-surveys' }],