Skip to content

feat: show CODEOWNERS diff when validate detects a stale file#107

Merged
dduugg merged 2 commits into
mainfrom
validate-show-codeowners-diff
Jun 8, 2026
Merged

feat: show CODEOWNERS diff when validate detects a stale file#107
dduugg merged 2 commits into
mainfrom
validate-show-codeowners-diff

Conversation

@dduugg

@dduugg dduugg commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

bin/codeownership validate previously reported only CODEOWNERS out of date. Run ... to update the CODEOWNERS file when the committed CODEOWNERS file was stale, with no indication of what differed. In CI this surfaced as an opaque message (wrapped in a Ruby RuntimeError stack trace by the code_ownership gem), forcing developers to re-run the tool locally just to discover the delta.

This PR appends a line-oriented diff between the on-disk CODEOWNERS file and the freshly generated one to the stale-file error, so the failure explains what is out of date.

Before

CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file

After

CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
The following changes are required (- current, + expected):
-# Outdated content to trigger validation error
-/app/old.rb @FooTeam
+# Annotations at the top of file
+/app/foo.rb @FooTeam
+# Team YML ownership
+/config/teams/foo.yml @FooTeam

Implementation

  • Added the similar crate for line-level diffing.
  • Error::CodeownershipFileIsStale now carries a diff string, computed by a new codeowners_diff helper that emits only changed lines with git-style -/+ prefixes (removals = present on disk but no longer expected; additions = expected but missing).
  • The diff is rendered under the existing headline via the error's messages().

Tests

  • Added unit tests for codeowners_diff (added/removed lines, empty file, identical files).
  • Updated the exact-match integration tests that assert the full validate output to include the new diff section.
  • Fixed a stale disclaimer header in the custom_executable_name and default_executable_name fixtures. They carried generated by "codeowners", which no longer matches the generator's generated by "bin/codeownership validate"; the mismatch was showing up as noise in the diff. Aligning the fixture header with the generated output keeps the diff focused on real ownership drift.

All tests, clippy --all-targets --all-features -D warnings, and fmt --check pass (enforced by the pre-commit hook).

Note

This improves the message the code_ownership Ruby gem surfaces, but the gem still wraps it in raise, so the stack trace seen in CI originates there, not in this repo.

`validate` previously reported only "CODEOWNERS out of date" with no
indication of what differed, forcing developers to re-run the tool
locally to discover the delta.

The stale-file error now includes a line-oriented diff between the
on-disk CODEOWNERS file and the freshly generated one (git-style
`-`/`+` prefixes, changed lines only), so CI output explains what is
out of date.
@dduugg dduugg requested a review from a team as a code owner June 8, 2026 18:21
@github-project-automation github-project-automation Bot moved this to Triage in Modularity Jun 8, 2026
@dduugg dduugg enabled auto-merge (squash) June 8, 2026 18:30
The custom_executable_name and default_executable_name CODEOWNERS
fixtures carried an outdated disclaimer header (`generated by
"codeowners"`) that no longer matches the generator's output
(`generated by "bin/codeownership validate"`). That mismatch showed up
as noise in the validate diff. Update the fixture headers to match the
generated disclaimer so the diff only reflects real ownership drift,
and restore the stricter executable-override assertion now that the
diff no longer contains "bin/codeownership".
@dduugg dduugg merged commit 597b13d into main Jun 8, 2026
8 checks passed
@dduugg dduugg deleted the validate-show-codeowners-diff branch June 8, 2026 19:01
@github-project-automation github-project-automation Bot moved this from Triage to Done in Modularity Jun 8, 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.

2 participants