Exclude a file or directory from CODEOWNERS
Asked Answered
T

1

14

I have a file structure like so:

foo/file1.c
foo/file2.c
foo/freeforall.c

My foogroup on GitHub needs to review changes to everything in foo except freeforall.c which is a file that anyone can touch without restriction, so it should not automatically add anybody as a reviewer when changes are made to it.

(In reality, whoever modifies freeforall.c just asks someone else on their own team to review their change.)

The Question

How can I do this with GitHub CODEOWNERS? The file looks like this right now:

foo @MyOrg/foogroup

What I Tried

GitHub explicitly says that the ! syntax is not supported, so that won't work:

foo @MyOrg/foogroup
!foo/freeforall.c

And there are too many files in the foo directory to explicitly include them individually. I could move freeforall.c into a different directory, but really I don't want to be having GitHub's CODEOWNER feature dictating how I organize my components. I want freeforall.c to be in the foo directory, that's where it belongs!

I also considered creating an emptygroup to assign that file to, but soon realized that now I'd be requiring that a group with zero members must approve PRs to that file which obviously would cause problems. 😂

foo @MyOrg/foogroup
foo/freeforall.c @MyOrg/emptygroup
Tophet answered 30/12, 2022 at 17:26 Comment(0)
H
24

The CODEOWNERS file takes the last matching line into account. You can make definitions with empty owners to specify paths/files without an owner.

Consequently, you can use the following lines to have all files in the foo directory owned by @MyOrg/foogroup except foo/freeforall.c:

foo @MyOrg/foogroup
foo/freeforall.c
Hullo answered 30/12, 2022 at 17:49 Comment(1)
AFAIK, the order is also important, because CODEOWNERS is read from bottom to top, and once a entry that determines the ownership of a file is found, the search for that file ownership is over. Therefore, place the entry for the ignored file below the entry defining ownership for the whole folder.Wineglass

© 2022 - 2024 — McMap. All rights reserved.