codeowners
codeowners copied to clipboard
Using '/' as a target in the CODEOWNERS file doesn't match anything.
This may be a user error on our part or a disagreement about the interpretation of the CODEOWNER spec.
If I have a CODEOWNERS file with the first line of / it doesn't match anything. Accord to one part of the spec, having a path ending with a / should match everything in the directory, and all sub-directories. By extension just a / should match everything in the repository.
from codeowners import CodeOwners
code_file = '''
... / @ORG/MyTeam
... '''
codeowner = CodeOwners(code_file)
codeowner.of("build.config")
[]
Does using /* do what you want?
With this lib I'm hoping to keep compatibility with github's behavior -- how does github handle the /?
The spec doesn't seem to mention /: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-syntax
It mentions it as one of the examples:
# In this example, @doctocat owns any file in the `/docs`
# directory in the root of your repository and any of its
# subdirectories.
/docs/ @doctocat
Which, by logical extension, would be / matches all the files in the root directory and any sub-directory. The example explicitly uses * as the default match all files in the whole repo.
Interesting, when I setup / as the pattern git's ignore setup doesn't consider /foo, bar/buzz, buzz.js, /a/b/c/d/e/f.txt to match
this test checks the pattern matching using git as the source of truth: https://github.com/sbdchd/codeowners/blob/6253a0c96aa6597dc2b2e7a2ae1e95a3e127d4b8/codeowners/test_codeowners.py#L513-L536