feat: inline ownership blocks (closes #3) - #179
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces two major features to codeowners-plus: inline ownership, which allows comment tags inside source files to assign ownership to specific line ranges, and ownership oracles, which allow external tooling to feed computed ownership requirements via JSON files. The code review identified critical security vulnerabilities in the inline ownership implementation. Specifically, renaming a file allows a PR to bypass base-side inline ownership protections because the base reader queries the new filename instead of the original filename. Additionally, the implementation exhibits fail-open behavior by silently ignoring file read and scanner errors, which could allow attackers to bypass required reviews. The reviewer recommended tracking the original filename across renames and treating parsing/reading failures as hard errors to ensure a fail-closed design.
bccb194 to
e95f0d0
Compare
e95f0d0 to
943d25b
Compare
…eviewer requirements)
943d25b to
3f02855
Compare
3f02855 to
56d9e71
Compare
Closes #3
Related PR(s)
Stacked on #178 (uses
NewFromFileOwnersand the sameMergeCodeOwnersmerge path); only the top commit is new. Supersedes #45, which can be closed.Related Issue(s)
Resolves #3. The issue floats AST-anchored comments (tree-sitter); this ships the language-agnostic line-range block form first, with AST anchoring noted in Future Features.
Summary / Background
Inline ownership: comment tags that mark a region of a source file as owned, so PR changes touching that region require the tagged owners' approval.
//and#prefixes work, tags are case-insensitive, and owners may be separated by commas or spaces. Owners inside one tag form an OR group, like a.codeownersline; overlapping blocks AND together. Enabled per-repo viaenable_inline_ownership = trueincodeowners.toml(default off).Touched blocks become per-file reviewer requirements, AND-merged into
.codeowners-derived ownership viacodeowners.MergeCodeOwners(the same mechanism asrequire_both_branch_reviewersand oracle files), so inline ownership can only ever add requirements.Design points:
git merge-base), not the base branch tip; otherwise line ranges drift whenever the base branch has advanced.Code Changes
pkg/inlineowners: block parser +Requirements(block/hunk intersection)internal/git:MergeBasehelper;DiffFile.BaseHunks/BaseFileName; both-path ignore-dirs filter;changesSincecarries base fieldsinternal/config:enable_inline_ownership(default false)internal/app:applyInlineOwnershipmerge step reading base blocks at the merge base