Skip to content

Replace Dependabot reviewers with CODEOWNERS - #214

Merged
timtebeek merged 3 commits into
mainfrom
tim/dependabot-reviewers-codeowners
Aug 22, 2026
Merged

Replace Dependabot reviewers with CODEOWNERS#214
timtebeek merged 3 commits into
mainfrom
tim/dependabot-reviewers-codeowners

Conversation

@timtebeek

@timtebeek timtebeek commented Aug 22, 2026

Copy link
Copy Markdown
Member

GitHub has removed the reviewers option from dependabot.yml and points users at CODEOWNERS instead.

ReplaceDependabotReviewersWithCodeowners is a ScanningRecipe that collects the reviewers from each updates entry, writes them to CODEOWNERS, and deletes the reviewers keys.

Mapping

Reviewers are mapped onto the manifest files Dependabot updates for that package-ecosystem + directory, not onto the whole directory. This matters: reviewers only ever applied to Dependabot PRs, whereas CODEOWNERS applies to every PR, so directory: / would otherwise hand a team ownership of the entire repository. github-actions is special-cased to /.github/workflows/.

- package-ecosystem: npm
  directory: /frontend
  reviewers:
    - acme/frontend

becomes

/frontend/package.json @acme/frontend
/frontend/package-lock.json @acme/frontend
/frontend/yarn.lock @acme/frontend
/frontend/pnpm-lock.yaml @acme/frontend

Do no harm

  • Unknown ecosystems keep their reviewers. Rather than falling back to a broader pattern, an ecosystem with no manifest mapping is skipped entirely, so a partial migration is visible rather than silently over-broad.
  • An unreadable CODEOWNERS blocks the whole migration. If a CODEOWNERS exists but is not parsed as plain text, nothing is deleted — otherwise the reviewers would be dropped with nowhere to record them.
  • Existing patterns are never overwritten. Only patterns the file does not already define are appended, so a second run is a no-op.
  • Existing CODEOWNERS is appended to, not replaced, honouring GitHub's precedence (.github/ > root > docs/). The codeownersPath option (default .github/CODEOWNERS) only applies when creating a new file.
  • The file's trailing-newline convention is preserved.

Testing

17 tests covering the multi-ecosystem example from the issue, directories (plural), flow sequences, @-prefixing of bare usernames, CODEOWNERS precedence, idempotence, and each of the do-no-harm guards above. Full build is green.

GitHub has removed the `reviewers` option from `dependabot.yml` and points
users at `CODEOWNERS` instead.

`ReplaceDependabotReviewersWithCodeowners` is a scanning recipe that collects
the reviewers from each `updates` entry, maps them onto the manifest files
Dependabot updates for that `package-ecosystem` and `directory`, and writes
them to `CODEOWNERS` before deleting the `reviewers` keys.

Mapping to manifests rather than to the whole directory keeps ownership as
narrow as the Dependabot configuration was; `CODEOWNERS` applies to every pull
request, not just Dependabot's. Ecosystems without a known manifest mapping
keep their `reviewers`, as do all entries when an existing `CODEOWNERS` cannot
be parsed as text, so the configuration is never dropped without a replacement.

Fixes #134
@timtebeek
timtebeek force-pushed the tim/dependabot-reviewers-codeowners branch from 277b6a9 to d6675ce Compare August 22, 2026 13:24
Review follow-ups on the previous commit:

- An unreadable lower-precedence `CODEOWNERS` no longer aborts the migration.
  A non-`PlainText` `docs/CODEOWNERS` used to set `codeownersIsAppendable`
  false even when `.github/CODEOWNERS`, the file GitHub actually honors, was
  perfectly appendable. Appendability is now decided by whichever file wins
  precedence, independent of the order sources are scanned.
- `github-actions` no longer ignores `directory`. A non-root directory points
  at a composite action definition, so it now maps to `action.yml`/`action.yaml`
  in that directory rather than over-granting `/.github/workflows/` and leaving
  the action itself unowned.
- Appended lines follow the existing file's line endings instead of always
  using LF, which produced mixed endings in a CRLF `CODEOWNERS`.
- The per-ecosystem `DeleteKey` loop, which re-traversed the document and
  recompiled a JsonPath for every migrated ecosystem, is now a single pass over
  an alternation.

Note that the previous commit message overstated one guarantee: when a
`CODEOWNERS` pattern is already owned by someone else, the Dependabot
`reviewers` are still removed without those reviewers being added to the
existing line, so that configuration is dropped rather than replaced.
When a pattern we want to add is already present with different owners, the
Dependabot `reviewers` were deleted without those reviewers being recorded
anywhere, silently dropping the configuration.

Appending a second line for the same pattern is not an option either, since
CODEOWNERS is last match wins and the new line would displace the owners
already there. Merge the reviewers into the existing line instead, so both
sets are kept. Owners already on the line are not repeated, so the recipe
stays idempotent.

This does not address overlapping globs: appending `/pom.xml @acme/backend`
below a `* @acme/everyone` still removes `@acme/everyone` as a required
reviewer of `pom.xml`. Resolving that needs CODEOWNERS glob matching rather
than exact pattern comparison.
@timtebeek
timtebeek merged commit 5f90912 into main Aug 22, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/dependabot-reviewers-codeowners branch August 22, 2026 14:15
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Replace usage of Dependabot's reviewers with CODEOWNERS

1 participant