DevSensei | Code Owners for Bitbucket

Want to have different CODEOWNERS file in subdirectories? (for monorepos)

Per default, only the Code Owners file at the top level of the repository is considered.

However, if your team has different projects in the same repository it can make sense to have a Code Owners file for different subdirectories. For that enable the CODEOWNERS.toplevel.subdirectory_overrides in the top-level Code Owners file. With that, any Code Owners file in a subdirectory determines the rules for that directory and it’s children. It replaces all rules set by the parent directories Code Owners file.


Here is an example:
In the top-level CODEOWNERS file:

CODEOWNERS.toplevel.subdirectory_overrides  enable

And then you can add Code Owner files for the subdirectories:

project-a/CODEOWNERS:

# Rules for Project A
* @@ProjectAOwners
src/*.java  @@JavaExperts
src/*.js    @@JavaScriptExperts

project-b/CODEOWNERS:

# Rules for Project B
* @@ProjectAOwners
src/*.cs  @@CSharpExperts

project-b/user-dos/CODEOWNERS:

# Rules for Project B's user documentation
* @@DocumentationTeam
*.md  @@DocumentationTeam
/images/* @@Designers