Repository navigation
Conversation
Adds -j/--json, which streams a JSON array with one object per file: its path, owners (empty when unowned) and the rule that matched it (pattern and line number, or null). --owner and --unowned filter it the same way as the text output, which is unchanged. Closes #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #36. Adds
-j/--jsonso the CLI can be used from scripts and CI without parsing the column-aligned text (the use case in #36, and the reason for the awk/YAML wrappers in #41).pattern,line). The rule makes it easy to answer "why does this file belong to this team?" and to spot rules that override earlier ones. A rule with no owners (an explicit unown) is still reported, andruleisnullwhen nothing matched.ownersis always an array (empty for unowned files), sojq '.[].owners[]'never hits null.--ownerand--unownedfilter the JSON exactly like the text output; no results prints[].printerinterface with a text and a JSON implementation, and a test pins the text format byte for byte.Tests: new
cmd/codeowners/main_test.go(7 tests: text output unchanged, JSON fields, null rule for unmatched files,--owner,--unowned, empty result, escaping).go vet ./...andgo test ./...pass locally (Go 1.26, Apple Silicon); the README gets a short--jsonsection with a jq example.I used AI assistance while writing this and reviewed and tested it locally.