Use this action to extract your CODEOWNER file information and check how individual files match CODEOWNER rules. It parses all the information and exports it as JSON. This output is available via the steps
output context.
This Actions outputs CODEOWNER file information, and optionally how individual files match specific rules.
In basic mode (default) it will only extract the information that can be found in the CODEOWNERS file and returns this information as an object. Use this Action in basic mode in your Actions workflow as follows:
- id: codeowners
uses: SvanBoxel/codeowners-action@v1
- run: |
echo ${{ steps.codeowners.outputs.codeowners }};
Example codeowners
object:
{
"dist/index.js": ["@foo-bot"],
"lib/*": ["@hubot"],
"src/main.ts": ["@hubot", "@svanboxel", "@foo-bot"]
}
When enabled, this Action checks how every file in your repository matches a specific CODEOWNER rule. The order of the CODEOWNERS rules defines (last matching pattern takes the most precedence), which rule matches which file.
- id: codeowner
uses: SvanBoxel/codeowners-action@v1
with:
file_match_info: 'true'
This will output the following (example) JSON format to the filematches
output variable:
{
"./bar/foo.cp": {
"rule_match": "*",
"owners": [ "@test" ]
},
"./lib/foo/bar.whop": {
"rule_match": "lib/foo/",
"owners": [ "@not-hubot" ]
},
"./src/main.ts": {
"rule_match": "src/main.ts",
"owners": [ "@hubot", "@svanboxel", "@foo-bot" ]
}
}
In the situation you want consume the above results directly from a file you can read ./codeowner-information.json
from the root of the repository. The format of this file follows the following format:
{
"codeownerInfo": {
"dist/index.js": ["@foo-bot"],
...
},
"fileMatches": {
"./bar/foo.cp": {
"rule_match": "*",
"owners": [ "@test" ]
},
...
}
}
By default, files without an owner will be ignored. Add the include_no_owners
option to include them in the report
- id: codeowner
uses: SvanBoxel/codeowners-action@v1
with:
file_match_info: 'true'
include_no_owners: 'true'
Will produce
{
"codeownerInfo": {
"dist/index.js": ["@foo-bot"],
...
},
"fileMatches": {
"./bar/foo.cp": {
"rule_match": "*",
"owners": [ "@test" ]
},
"./orphan-file.txt": {
"rule_match": null,
"owners": [ ]
},
...
}
}
If your CODEOWNERS file isn't in the root of your repository, but for instead in the .github
directory, you can change the path by using the path parameter:
- id: codeowner
uses: SvanBoxel/codeowners-action@v1
with:
path: './.github/CODEOWNERS'
Install the dependencies
$ npm install
Build the typescript and package it for distribution
$ npm run build && npm run package
Run the tests ✔️
$ npm test
PASS ./index.test.js
✓ throws invalid number (3ms)
✓ wait 500 ms (504ms)
✓ test runs (95ms)
...
If you have suggestions for how this GitHub Action could be improved, or want to report a bug, open an issue! We'd love all and any contributions.
MIT © 2020 Sebass van Boxel hello@svboxel.com