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

Fix #6449: Added check for CODEOWNERS to ensure that the most important rules are at the end. #6560

Merged
merged 16 commits into from
Jun 13, 2019
Merged

Fix #6449: Added check for CODEOWNERS to ensure that the most important rules are at the end. #6560

merged 16 commits into from
Jun 13, 2019

Conversation

YashJipkate
Copy link
Contributor

Explanation

Fixes #6449. A check is added to ensure the most important rules/patterns are at the bottom of the CODEOWNERS file.

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR follows the style guide.
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue.

@codecov-io
Copy link

codecov-io commented Apr 6, 2019

Codecov Report

Merging #6560 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 419a0f2...6679d6c. Read the comment docs.

@YashJipkate
Copy link
Contributor Author

Hi, @apb7 Could you PTAL!
Thanks!

@YashJipkate
Copy link
Contributor Author

Hi @apb7 Ping!

Copy link
Contributor

@apb7 apb7 left a 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 Show resolved Hide resolved
@@ -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 = ([
Copy link
Contributor

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:

  1. Please add comments explaining why we are populating this list.
  2. Where are we checking whether the paths in CODEOWNER_IMPORTANT_PATHS are towards the end of the CODEOWNERS file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the comments. PTAL!

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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 Show resolved Hide resolved
@YashJipkate YashJipkate requested a review from apb7 April 19, 2019 09:31
@@ -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 = ([
Copy link
Contributor

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.

@apb7
Copy link
Contributor

apb7 commented Apr 19, 2019

@YashJipkate, did you do this as well?

Please manually check these changes by deliberately making such an error, locally. Thanks!

Please answer all queries before requesting another review :)

@apb7 apb7 assigned YashJipkate and unassigned apb7 Apr 19, 2019
@YashJipkate
Copy link
Contributor Author

Sorry for that @apb7.
Yes I have tried this manually on my local by moving the important rules upward such that they are not at the end of the file, and the linter reported the same too.
Thanks!

@YashJipkate YashJipkate assigned apb7 and unassigned YashJipkate Apr 20, 2019
@YashJipkate YashJipkate requested a review from apb7 April 20, 2019 06:29
Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks, @YashJipkate!

@@ -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 = ([
Copy link
Contributor

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!

@YashJipkate
Copy link
Contributor Author

Hi @apb7, Is this good to merge?
Thanks!

Copy link
Member

@DubeySandeep DubeySandeep left a 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 Show resolved Hide resolved
@@ -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
Copy link
Member

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!

Copy link
Contributor Author

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)

Copy link
Contributor

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 :))

Copy link
Member

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?

Copy link
Contributor Author

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

# 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(
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

image
I tried adding a new file in the CODEOWNERS critical section. (without doing any changes in pre_commit_linter.py)

What should be the expected behavior?
I got this:
image

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

# 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):
Copy link
Member

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?)

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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!

@DubeySandeep DubeySandeep assigned YashJipkate and unassigned apb7 Apr 27, 2019
@YashJipkate YashJipkate requested a review from seanlip as a code owner May 1, 2019 07:46
Copy link
Member

@DubeySandeep DubeySandeep left a 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")

Copy link
Member

@seanlip seanlip left a 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 :) )

@oppiabot
Copy link

oppiabot bot commented Jun 5, 2019

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.
If you are still working on this PR, please make a follow-up commit within 4 days (and submit it for review, if applicable). Please also let us know if you are stuck so we can help you!

@oppiabot oppiabot bot added the stale label Jun 5, 2019
@oppiabot oppiabot bot removed the stale label Jun 6, 2019
@apb7
Copy link
Contributor

apb7 commented Jun 8, 2019

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!

@YashJipkate
Copy link
Contributor Author

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.

@seanlip
Copy link
Member

seanlip commented Jun 9, 2019

Hi @YashJipkate, I think you can still address that comment. The change is not that big. Are you planning to do so?

@YashJipkate
Copy link
Contributor Author

Hi @seanlip Sorry for the delay, I have changed the working rule to make way for sets. PTAL!
Thanks!

Copy link
Member

@seanlip seanlip left a 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!


Arguments:
important_patterns: list(str). List of the important
paths/rules for CODEOWNERS file.
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have generalized "patterns".

paths/rules for CODEOWNERS file.

Returns:
bool. Status of failure.
Copy link
Member

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.

Copy link
Contributor Author

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.

' 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 '
Copy link
Member

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?

Copy link
Contributor Author

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.
Copy link
Member

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

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 '
Copy link
Member

Choose a reason for hiding this comment

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

since --> section since

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@YashJipkate YashJipkate requested a review from seanlip June 13, 2019 03:49
@YashJipkate YashJipkate assigned seanlip and unassigned YashJipkate Jun 13, 2019
Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @YashJipkate !

@seanlip seanlip removed their assignment Jun 13, 2019
@seanlip
Copy link
Member

seanlip commented Jun 13, 2019

@DubeySandeep PTAL. Thanks!

@seanlip
Copy link
Member

seanlip commented Jun 13, 2019

@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

@YashJipkate
Copy link
Contributor Author

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.

@seanlip
Copy link
Member

seanlip commented Jun 13, 2019

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.

@YashJipkate
Copy link
Contributor Author

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.

@seanlip
Copy link
Member

seanlip commented Jun 13, 2019

OK cool! Sounds good then :D

@YashJipkate
Copy link
Contributor Author

@DubeySandeep The checks pass now. Could this be merged?
Thanks!

@DubeySandeep DubeySandeep merged commit 61a6350 into oppia:develop Jun 13, 2019
@YashJipkate YashJipkate deleted the codeowner-imp-rules branch June 13, 2019 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint check for CODEOWNERS to ensure that the most important rules are at the end.
5 participants