Order of owners in codeowners file

I have my codeowners file set up and grouped by teams, so something like this:

# Team A
/engn/headers/sql_file1.in @ORG/team-a
/engn/headers/sql_file2.in @ORG/team-a
/engn/headers/sql_file3.in @ORG/team-a
/engn/headers/pdSql_file1.in @ORG/team-a

#Team B
/engn/headers/sqp_file1.in @ORG/team-b
/engn/headers/sqp_file2.in @ORG/team-b
/engn/headers/sqp_file3.in @ORG/team-b
/engn/headers/pd* @ORG/team-b

Who will be the owner of pdSql_file1.in ? The docs say the order matters, so I would assume since team-b comes after team-a, it’s general ownership overwrites the specific ownership of team-a.

Note I don’t want teams sharing the ownership of that file, it should be owned solely by team-a.

Is grouping by teams not the correct thing to do?

1 Like

Hello @DenizTC and welcome to the community.

Yes, order matters in the CODEOWNERS file, specifically lines that come later override lines that appear earlier in the file. In the example in the documentation, this is taken advantage of by starting with the least specific rule and then following with increasingly more specific rules as in this excerpt:

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
*       @global-owner1 @global-owner2

# Order is important; the last matching pattern takes the most
# precedence. When someone opens a pull request that only
# modifies JS files, only @js-owner and not the global
# owner(s) will be requested for a review.
*.js    @js-owner

It isn’t specifically incorrect but it may mean that you’ll have to write more rules to achieve the same effect than if you worked with the way the CODEOWNERS file is interpreted. So you may want to reorder your file like this to achieve your stated goal:

# PD files
/engn/headers/pd* @ORG/team-b

# PD exceptions
/engn/headers/pdSql_file1.in @ORG/team-a

# etc ...
2 Likes