Skip to content

Exempt specific files from Codeowners rules

Problem to solve

In some cases an organization wants the strict control provided by codeowners on most files, but want to exclude a small number of files from this. For example, updating a pom file as part of a Maven CI pipeline.

Intended users

Proposal

Introduce a new syntax !#{path} for CODEOWNERS to exclude files from the current section. Any lines starting with ! will exclude matching paths form other rules within the current section.

* @group-x
!*.rb

[Ruby]
*.rb @ruby-devs
!/config/*

The default group would match all files excluding ruby files The Ruby group would match all ruby files except any inside the /config directory

Research

We performed a spike [SPIKE] Refine `Exempt specific files from Code... (#497801 - closed) to research how we would implement this.

  1. Add regex to identify exclusion entries within CODEOWNERS file within Gitlab::CodeOwners::File#parse_entry
  2. Refactor MergeRequests::SyncCodeOwnerApprovalRules#execute to apply the exclusions

Out of scope

.gitignore allows excluding a file and then reincluding it further down. We will not support this as it introduces a lot of complexity. This may be implemented in future.

Adding errors when the exclusions are not well formatted e.g. !/path/*.rb @user or !*.rb !*.js

Edited by Joe Woodward