A CLI and Go library for GitHub's CODEOWNERS file.
The codeowners CLI identifies the owners for files in a local repository or directory.
If you're on macOS, you can install the CLI from the homebrew tap.
$ brew tap hmarr/tap
$ brew install codeownersOtherwise, grab a binary from the releases page or install from source with go install:
$ go install github.com/hmarr/codeowners/cmd/codeowners@latestBy default, the command line tool will walk the directory tree, printing the code owners of any files that are found.
$ codeowners --helpusage: codeowners <path>... -f, --file string CODEOWNERS file path -h, --help show this help message -o, --owner strings filter results by owner -u, --unowned only show unowned files (can be combined with -o)
$ lsCODEOWNERS DOCUMENTATION.md README.md example.go example_test.go
$ cat CODEOWNERS*.go @example/go-engineers*.md @example/docs-writersREADME.md product-manager@example.com
$ codeownersCODEOWNERS (unowned)README.md product-manager@example.comexample_test.go @example/go-engineersexample.go @example/go-engineersDOCUMENTATION.md @example/docs-writersTo limit the files the tool looks at, provide one or more paths as arguments.
$ codeowners *.mdREADME.md product-manager@example.comDOCUMENTATION.md @example/docs-writersPass the --owner flag to filter results by a specific owner.
$ codeowners -o @example/go-engineersexample_test.go @example/go-engineersexample.go @example/go-engineersPass the --unowned flag to only show unowned files.
$ codeowners -uCODEOWNERS (unowned)A package for parsing CODEOWNERS files and matching files to owners.
$ go get github.com/hmarr/codeownersFull documentation is available at pkg.go.dev.
Here's a quick example to get you started:
package main
import (
"fmt""log""os""github.com/hmarr/codeowners"
)
funcmain() {
file, err:=os.Open("CODEOWNERS")
iferr!=nil {
log.Fatal(err)
}
ruleset, err:=codeowners.ParseFile(file)
iferr!=nil {
log.Fatal(err)
}
rule, err:=ruleset.Match("path/to/file")
iferr!=nil {
log.Fatal(err)
}
fmt.Printf("Owners: %v\n", rule.Owners)
}