Propiedad del Código

CODEOWNERS · Inner source

Escrito por Darjus Kazakevic · revisado el

Write down who approves each change, or the loudest objector decides.

Every codebase has ownership; the question is whether it is written down. Left unwritten, whoever notices a change and objects enforces it. That produces uneven reviews, surprise vetoes, and paths nobody touches because nobody knows who must agree.

Martin Fowler names three levels. Strong: one team approves and others propose. Weak: an owning team is notified, but others may merge. Collective: anyone may change anything. Most codebases need different levels in different places. GitHub and GitLab both read a CODEOWNERS file that maps each path to its owners.

En esencia — State for each path whether ownership is strong, weak or collective, so approval rights are a written policy, not a surprise in review.

Cuándo recurrir a él

Recurre a él cuando

  • Reviews stall because nobody knows whose approval a change needs
  • A shared kernel or migrations folder needs a named, enforced gate
  • A monorepo where many teams work in one repository

Reconsidéralo cuando

  • One small team where everyone already reviews everything
  • Strong ownership on a path that several teams change every week
  • As a replacement for talking; owners still need to answer quickly

Conceptos clave

Strong ownership
One team must approve every change to a path. Others may open pull requests, but cannot merge without the owner's approval.
Weak ownership
An owning team is notified and usually reviews, but others may merge with any approval. Most code should look like this.
Collective ownership
Anyone may change any line. It works in a small team with good tests and shared habits. It fails when nobody feels responsible.
CODEOWNERS file
A file that maps path patterns to owners. The forge requests reviews from them and, with branch protection, requires their approval.

Reglas de diseño

Name an owner for every path, even “anyone”
Start with a catch-all owner, then mark collective paths explicitly. An unowned path is not free to change. It waits for a reviewer nobody named, and the loudest objector fills the gap.
Reserve strong ownership for risky paths
Default to weak ownership. Require owner approval only where a bad change is costly, such as a shared kernel, migrations or CI workflows. Otherwise every team becomes a queue.
Check the owners file like code
Teams get renamed and split. Check CODEOWNERS in CI so every listed team exists and has write access. Otherwise review requests silently go to nobody.

Errores habituales

  • The catch-all line placed last. It matches everything, so it overrides every specific rule above it.
  • A renamed team still listed in the file. GitHub ignores the line, and the gate quietly disappears.
  • Strong ownership everywhere. Every cross-team change waits days for an approval.
  • No catch-all at all. New folders have no owner, and their pull requests wait for a reviewer nobody named.