-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix #6449: Added check for CODEOWNERS to ensure that the most important rules are at the end. #6560
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #6560 +/- ##
========================================
Coverage 95.32% 95.32%
========================================
Files 371 371
Lines 50558 50558
========================================
Hits 48193 48193
Misses 2365 2365 Continue to review full report at Codecov.
|
Hi, @apb7 Could you PTAL! |
Hi @apb7 Ping! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @YashJipkate, sorry for the delay. Please manually check these changes by deliberately making such an error, locally. Thanks!
scripts/pre_commit_linter.py
Outdated
@@ -2178,6 +2190,23 @@ def _check_codeowner_file(self): | |||
print ('WARNING! %s/%s is not covered under ' | |||
'CODEOWNERS' % (root, file_name)) | |||
|
|||
# Checks that the most important rules/patterns are at the bottom | |||
# of the CODEOWNERS file. | |||
important_path_match_bool_list = ([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of points here:
- Please add comments explaining why we are populating this list.
- Where are we checking whether the paths in
CODEOWNER_IMPORTANT_PATHS
are towards the end of the CODEOWNERS file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the comments. PTAL!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you haven't answered this:
Where are we checking whether the paths in CODEOWNER_IMPORTANT_PATHS are towards the end of the CODEOWNERS file?
You are only checking the lines in CODEOWNER_IMPORTANT_PATHS as far as I understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we are checking for the ones in CODEOWNER_IMPORTANT_PATHS
which contains the important rules.
Does this seem wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. Looks good!
scripts/pre_commit_linter.py
Outdated
@@ -2178,6 +2190,23 @@ def _check_codeowner_file(self): | |||
print ('WARNING! %s/%s is not covered under ' | |||
'CODEOWNERS' % (root, file_name)) | |||
|
|||
# Checks that the most important rules/patterns are at the bottom | |||
# of the CODEOWNERS file. | |||
important_path_match_bool_list = ([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you haven't answered this:
Where are we checking whether the paths in CODEOWNER_IMPORTANT_PATHS are towards the end of the CODEOWNERS file?
You are only checking the lines in CODEOWNER_IMPORTANT_PATHS as far as I understand.
@YashJipkate, did you do this as well?
Please answer all queries before requesting another review :) |
Sorry for that @apb7. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks, @YashJipkate!
scripts/pre_commit_linter.py
Outdated
@@ -2178,6 +2190,23 @@ def _check_codeowner_file(self): | |||
print ('WARNING! %s/%s is not covered under ' | |||
'CODEOWNERS' % (root, file_name)) | |||
|
|||
# Checks that the most important rules/patterns are at the bottom | |||
# of the CODEOWNERS file. | |||
important_path_match_bool_list = ([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. Looks good!
Hi @apb7, Is this good to merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YashJipkate, I went through this PR and left a few comments can you please check! :)
scripts/pre_commit_linter.py
Outdated
@@ -2178,6 +2192,30 @@ def _check_codeowner_file(self): | |||
print ('WARNING! %s/%s is not covered under ' | |||
'CODEOWNERS' % (root, file_name)) | |||
|
|||
# Checks that the most important rules/patterns are at the bottom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to check code owner function is already 150~ lines big can we create a sperate function for checking important rule or pattern and call this over here? will it be possible?
This will also move this many comments into the new function docstring!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sounds good. Will do that!
Also, @apb7, do you agree on this too? (since you are always in favor of clubbing similar functionalities to a pre-existing function if any)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @DubeySandeep here. We can modularize this code. (As an FYI -- I am in favor of clubbing similar checks so that we do not end up repeating stuff. If there's no repetition, then it's totally fine :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YashJipkate, is this comment resolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @DubeySandeep This is resolved now. Sorry for the delay.
PTAL! Thanks
scripts/pre_commit_linter.py
Outdated
# matching the last lines of the CODEOWNERS file with the list of | ||
# the important CODEOWNERS paths. | ||
important_path_match_bool_list = ([ | ||
imp_path in path_lines[-1 * len( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is someone adds a new pattern(important) in the top of the list, will this check ask users to add this list over here or will this check fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the check will fail. The 'n'-list and the last 'n' lines need to be in sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is happening because of the new important rules that are not in sync with the CODEOWNER_IMPORTANT_PATHS
list. The (outdated) list checks for the last n-lines of the CODEOWNERS file in which the erring pattern is not found and hence the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy that it's failing but the error message is something unrelated. Can we do something for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have modified the error message. PTAL!
Thanks.
scripts/pre_commit_linter.py
Outdated
# This condition checks that all the values in the boolean list are | ||
# True. This ensures that the last 'n' lines of the CODEOWNERS file | ||
# matches with the 'n'-element list of important CODEOWNER paths. | ||
if not all(important_path_match_bool_list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also look for all the value in the list i.e, what we have done in line 2209, if yes then can we just have the for loop? (is there any benefit of doing this check?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this check so that the loop runs only when it is needed. At present the list is small so it may not seem that big a problem but in future when it enlarges it might be redundant to unnecessary run the loop.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, we are going to run through all the values, isn't it?
Like if there is any false in the list we will cover the entire list through the for loop and if all the values are true we are going to loop through all the values via all(...)
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right about this. Will remove this. Thanks for pointing out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm marking this to "Request changes")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (but only as code owner of CODEOWNERS :) )
Hi @YashJipkate, I'm going to mark this PR as stale because it hasn't had any updates for 7 days. If no further activity occurs within 4 days, it will be automatically closed so that others can take up the issue. |
Hi @YashJipkate, have you addressed the last round of review comments? If yes, can you please reply to them inline so that the reviewers have an idea. This PR has been standing for quite some time now. Can you please look into this? Thanks! |
Hi @apb7, Sorry for this PR getting stale. I have addressed all the comments except this #6560 (comment) since that requires complete restructure of the method I have used. |
Hi @YashJipkate, I think you can still address that comment. The change is not that big. Are you planning to do so? |
Hi @seanlip Sorry for the delay, I have changed the working rule to make way for sets. PTAL! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, just some very minor comments left. Thanks @YashJipkate!
scripts/pre_commit_linter.py
Outdated
|
||
Arguments: | ||
important_patterns: list(str). List of the important | ||
paths/rules for CODEOWNERS file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you say "paths/rules", but in the docstring you say "rules/patterns", and to make things even more confusing, this arg is called "important_patterns".
Please could you figure out what is actually being referenced, and amend the docstrings/argname/descriptions accordingly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have generalized "patterns".
scripts/pre_commit_linter.py
Outdated
paths/rules for CODEOWNERS file. | ||
|
||
Returns: | ||
bool. Status of failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool. Whether the CODEOWNERS "important rule" check passes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"- check fails" would be more appropriate I guess since the bool actually has the status of failure.
scripts/pre_commit_linter.py
Outdated
' section.' % CODEOWNER_FILEPATH) | ||
failed = True | ||
if len(codeowner_important_paths_set) != len(CODEOWNER_IMPORTANT_PATHS): | ||
print('scripts/pre_commit_linter.py --> Duplicate pattern found in ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: pattern --> patterns for consistency with previous message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
print('scripts/pre_commit_linter.py --> Duplicate pattern found in ' | ||
'CODEOWNER_IMPORTANT_PATHS list.') | ||
failed = True | ||
# Check missing rules by set difference operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a blank line above this. Divide your code into meaningful "blocks".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
scripts/pre_commit_linter.py
Outdated
failed = True | ||
for rule in list_minus_critical_rule_section_set: | ||
print('%s --> Rule \'%s\' is not present in the \'Critical files\' ' | ||
'section. Please place it under the \'Critical files\' since ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since --> section since
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @YashJipkate !
@DubeySandeep PTAL. Thanks! |
@YashJipkate qq -- don't the lint checks run before you push? Just wondering how that slipped through and how we can prevent it in the future. /cc @oppia/dev-workflow-team |
Actually, in this copy of my repo, there was some problem regarding the python version (since this my new system) and hence the linter does not work (probably). The other copy works fine as it had the correct python version installed. |
Ah, ok. If you feel like we need to fix the pre-commit linter to guard against this issue, it might be worth doing that. Might save a lot of time in future. |
Thanks @seanlip. But fortunately, I no longer use that copy and use the one which has the linter running. This is an old PR and hence was in the old copy. |
OK cool! Sounds good then :D |
@DubeySandeep The checks pass now. Could this be merged? |
Explanation
Fixes #6449. A check is added to ensure the most important rules/patterns are at the bottom of the CODEOWNERS file.
Checklist
python scripts/pre_commit_linter.py
andbash scripts/run_frontend_tests.sh
.