codeowners-checker icon indicating copy to clipboard operation
codeowners-checker copied to clipboard

Feature: Cleanup command

Open dennissivia opened this issue 5 years ago • 3 comments

After some discussion I am suggesting to add a cleanup command to tackle the following problems:

Problem

When a CODEOWNERS file becomes bigger the following problems arise:

  • Duplicate patterns
  • Hard to find what belongs to the same owner (lack of sorting)
  • Obsolete patterns (no file matches the given pattern)

Proposal

Add a new command --cleanup to do the following things.

  • Sort the file based on the rules listed below (See sorting
  • Remove duplicate patterns (only full duplications)
  • Expand each pattern and if finds 0 files, remove the pattern

Sorting

Our initial discussion lead to the following proposal:

  • Sort (and thus group) by owner
  • Within one owner sort patterns alphabetically

Related issues

#21 also asks for some of these topics.

dennissivia avatar May 25 '20 10:05 dennissivia

Hi, I'm tackling this issue right now but I'd like to discuss about the sorting thing.

When generating the new CODEOWNERS file after sorting, should we keep the comments?

Comments right now are being treated as part of the "syntax" because of the "grouping" feature. I'm afraid it may be hard to keep comments and still order by the owner.

My idea was to simply start a new codeowners file from scratch and just "group" with the name of the owner, like such

# Owned by @owner_a
file_b @owner_a
file_c @owner_a

# Owned by @owner_b
file_a @owner_b

Any suggestions on how to do this in a simple way?

bamorim avatar Jun 03 '20 17:06 bamorim

Also, how should we handle patterns with multiple owners?

The only reasonably solution is to treat a collection of owners as a "unique owner" when grouping

Something like

# Owned by @owner_a and @owner_b
file_d @owner_a @owner_b

# Owned by @owner_a
file_b @owner_a
file_c @owner_a

# Owned by @owner_b
file_a @owner_b

But we still need to think how to sort them.

bamorim avatar Jun 03 '20 17:06 bamorim

Another question: should we check for consistency on this command as well? Or just rewrite the file?

bamorim avatar Jun 03 '20 18:06 bamorim