A GitHub CODEOWNERS parser and matcher implemented as an mq module.
- Parses
CODEOWNERSfiles (*,**,[...]gitignore-style path patterns) - Looks up owners for a given path, applying GitHub's "last matching pattern wins" rule
- Renders a Markdown table summarizing all patterns and their owners
Copy codeowners.mq to your mq module directory, or place it anywhere and reference it with -L.
cp codeowners.mq ~/.local/mq/config/If mq was built with the http-import feature, you can import directly from GitHub without any local setup:
mq -I raw 'import "github.com/harehare/codeowners.mq" | codeowners::codeowners_for(., "src/index.js")' CODEOWNERSPin to a specific release with @vX.Y.Z:
mq -I raw 'import "github.com/harehare/codeowners.mq@v0.1.0" | codeowners::codeowners_for(., "src/index.js")' CODEOWNERSmq -L /path/to/modules -I raw \
'import "codeowners" | codeowners::codeowners_for(., "src/index.js")' CODEOWNERSIf you copied it to the mq built-in module directory:
mq -I raw 'import "codeowners" | codeowners::codeowners_for(., "src/index.js")' CODEOWNERS| Function | Description |
|---|---|
codeowners_parse(input) |
Parses CODEOWNERS contents into an array of pattern entries |
codeowners_owners(entries, path) |
Returns the owners array for path (last matching pattern wins); [] if unowned |
codeowners_for(text, path) |
Parses text and looks up owners for path in one call |
codeowners_is_unowned(entries, path) |
true if no pattern matches path |
codeowners_to_markdown_table(entries) |
Renders a Markdown table of pattern / owners, in file order |
Each pattern entry is a dict: {"pattern": <original glob>, "regex": <compiled regex>, "owners": [<string>, ...]}.
path is matched as given — a leading / is stripped, but callers are expected to pass a path relative to the repository root using / separators.
Given CODEOWNERS:
# default owner
* @global-owner
# JS/TS
*.js @js-owner @org/js-team
*.tsx @frontend-team
# docs
/docs/ docs@example.com
mq -I raw 'import "codeowners" | codeowners::codeowners_for(., "src/app.js")' CODEOWNERS
# => ["@js-owner", "@org/js-team"]
mq -I raw 'import "codeowners" | codeowners::codeowners_for(., "docs/guide.md")' CODEOWNERS
# => ["docs@example.com"]
mq -I raw 'import "codeowners" | codeowners::codeowners_for(., "README.md")' CODEOWNERS
# => ["@global-owner"]
mq -I raw 'import "codeowners" | codeowners::codeowners_to_markdown_table(codeowners::codeowners_parse(.))' CODEOWNERS
# | Pattern | Owners |
# | --- | --- |
# | * | @global-owner |
# | *.js | @js-owner, @org/js-team |
# | *.tsx | @frontend-team |
# | /docs/ | docs@example.com |Requires mq v0.7 or later.
MIT