sirosen / texthooks

pre-commit hooks for checking text file contents
Other
14 stars 3 forks source link

codeowners groups with default users sorted incorrectly #80

Closed adam-moss closed 2 weeks ago

adam-moss commented 3 months ago

When a codeowners file containers mandatory or optional groups with default users the current sorting implementation breaks the codeowners file.

E.g.

* @user1

## core product files
[Product Team] @user1
/path/to/file/one

## specific content approvals

[Team 1] @user2
/path/to/file/two

[Team 2][2] @user3 @user4
/path/to/file/three

^[Team 3][1] @user3 @user4
/path/to/file/four

## this file

/.gitlab/CODEOWNERS @user1

results in

* @user1

## core product files
[Product @user1 Team]
/path/to/file/one

## specific content approvals

[Team 1] @user2
/path/to/file/two

[Team 2][2] @user3 @user4
/path/to/file/three

^[Team 3][1] @user3 @user4
/path/to/file/four

## this file

/.gitlab/CODEOWNERS @user1
sirosen commented 3 months ago

mandatory or optional groups with default users

I'm not familiar with this codeowners feature -- it looks like it's specific to GitLab. GitHub does not have such a feature as far as I can see.

I'm happy to work on or take a patch for this, but I think it should be opt-in with a dedicated arg. The current idea I like best is --variant=gitlab, which would allow for other variants (e.g., --variant=github) if the syntaxes supported by various platforms starts to diverge further.

sirosen commented 2 weeks ago

This should now be supported in v0.6.7 . You'll need to add --dialect gitlab to your alphabetize-codeowners usage, but it picks up on the gitlab-specified section headers and sorts any default owners declared for a section.

Let me know if you run into any issues using it!