CODEOWNERS (/.github/CODEOWNERS) định nghĩa ai là owner của file/directory — GitHub tự động add họ làm required reviewers khi PR chạm vào files đó.
Format:
# Syntax: pattern @user-or-team
* @default-reviewer # catch-all
/src/auth/ @security-team # auth code
/src/payments/ @payments-team @cto # payments: 2 owners
*.sql @dba-team # all SQL files
/docs/ @tech-writer # documentation
/.github/ @devops-team # CI/CD configs
/package.json @lead-dev # dependency changesRules:
- Patterns match như .gitignore — last matching rule wins
- Cần enable "Require review from Code Owners" trong branch protection
- Team owners: @org/team-name (không phải individual)
Pitfalls:
- Quá nhiều owners → bottleneck (mọi PR cần 5 người approve)
- Không review CODEOWNERS định kỳ → departed employees vẫn là required reviewers
- Forgetting catch-all * rule → new files có thể không có owner
Best practice: ít owners per path, dùng teams thay vì individuals, review CODEOWNERS mỗi quarter.