I work for a company that likes to PR review everything. I also work for a company that has a staff with an attention to well-formatted, pretty files. If a change is made to a CODEOWNERS file that would require the file to be re-columned, then the PR would show all lines changed. This would prompt a PR reviewer to have to either click "approve" without considering the content of the file, or actually read the entire CODEOWNERS file again. So, I wrote codeowner-gen with this problem in mind.
codeowner-gen takes a well-formatted yaml file, and does a few things:
- You specify a bunch of paths and one or more owners per path, and it will alphabetize it and ensure that all records are spaced so that output is columnar,
- unless you specify one or more of the objects as "grouped", in which case it will alphabetize and then group the records together,
- it processes the Owners you've listed and I might eventually enable the app to validate that the user/team you've specified actually exists,
- You can specify a comment, per line, and it will render it out for you.
The output is then rendered to the CODEOWNERS file for you, alphabetized and/or grouped by your grouping specification, and properly columned so that the text columns align.
With this workflow, a reviewer can see that the first line of the CODEOWNERS file is a codeowner-gen rendered file and ignore it, in favor of reviewing the changes in the codeowners.yaml file instead. That file, being yaml, will show changes in a more sane and easy-to-digest format for a PR reviewer.
cargo install --git https://github.com/PeterGrace/codeowner-gen.git --tag v0.1.6
codeowner-gen
in a directory with a well-formatted codeowners.yaml will output a CODEOWNERS file. If you want to specify an alternate yaml, use -i
option.
Given a yaml file like below:
---
entries:
- path: "alpha"
comment: "Alphabetically speaking, this probably is coming early on"
group: "phonetic"
owners:
- "@petergrace"
- path: "zebra"
comment: "This is likely the last entry"
group: "phonetic"
owners:
- "@petergrace"
- path: "*"
group: "main"
owners:
- "@petergrace"
- path: "target/debug/deps/itoa-*"
owners:
- "pete.grace@gmail.com"
- "@petergrace"
- "@petergrace/teamname"
The codeowners-gen program will output:
# Generated by codeowner-gen v0.1.0/2db3d0dbd7ece3182de63b440b07379cb19b49cd
#
####### BEGIN UNGROUPED
target/debug/deps/itoa-* pete.grace@gmail.com @petergrace @petergrace/teamname
####### BEGIN GROUP MAIN
* @petergrace
### END GROUP MAIN
####### BEGIN GROUP PHONETIC
# Alphabetically speaking, this probably is coming early on
alpha @petergrace
# This is likely the last entry
zebra @petergrace