-
-
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
Changes from 1 commit
7423c00
bea64b0
c2c94e8
35abb55
9d2e3c3
2df107a
78d4b16
644c6a2
026e091
65a4c8f
596f823
0b5b9b9
1c3f7c4
7e2ad7c
283997d
6679d6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2235,39 +2235,39 @@ def _check_bad_patterns(self): | |
return summary_messages | ||
|
||
def check_for_important_rules_at_bottom_of_codeowners( | ||
self, imp_patterns, failed): | ||
self, important_patterns): | ||
"""Checks that the most important rules/patterns are at the bottom | ||
of the CODEOWNERS file. | ||
|
||
Arguments: | ||
imp_patterns: list(str). List of the important | ||
important_patterns: list(str). List of the important | ||
paths/rules for CODEOWNERS file. | ||
failed: bool. Current status of failure. | ||
|
||
Returns: | ||
bool. Status of failure. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
""" | ||
|
||
failed = False | ||
# The following condition checks for extra rules in the critical | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it perhaps be cleaner to:
I think that would be cleaner and easier to read than printing everything individually and doing lots of for loops. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @seanlip I was too thinking of doing this cleanly using (Repeated pattern in the ciriticle path patterns.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call! A common pattern for this is to start by doing it with a list, then convert it to set and check if the lengths match. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. PTAL if it matches with your thoughts @seanlip @DubeySandeep |
||
# files section in the .github/CODEOWNERS file. | ||
if len(imp_patterns) > len( | ||
if len(important_patterns) > len( | ||
CODEOWNER_IMPORTANT_PATHS): | ||
important_path_match_bool_list = ([ | ||
imp_path in CODEOWNER_IMPORTANT_PATHS | ||
for imp_path in imp_patterns]) | ||
important_path in CODEOWNER_IMPORTANT_PATHS | ||
for important_path in important_patterns]) | ||
for index, bool_value in enumerate( | ||
important_path_match_bool_list): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we traverse the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I think that having a separate variable for this would be more readable similar to the modularization we did for this function as we concluded that splitting up would be better for the end user. |
||
if not bool_value: | ||
print ('%s --> The rule \'%s\' is not an important ' | ||
'rule. Please place it before the critical ' | ||
'files section.' % ( | ||
CODEOWNER_FILEPATH, | ||
imp_patterns[index])) | ||
important_patterns[index])) | ||
failed = True | ||
else: | ||
important_path_match_bool_list = ([ | ||
imp_path in imp_patterns | ||
for imp_path in CODEOWNER_IMPORTANT_PATHS]) | ||
important_path in important_patterns | ||
for important_path in CODEOWNER_IMPORTANT_PATHS]) | ||
# This condition checks that all the values in the boolean list | ||
# are True. This ensures that the critical files of the | ||
# CODEOWNERS file matches with the CODEOWNER_IMPORTANT_PATHS. | ||
|
@@ -2303,7 +2303,7 @@ def _check_codeowner_file(self): | |
# Checks whether every pattern in the CODEOWNERS file matches at | ||
# least one dir/file. | ||
critical_file_section_found = False | ||
imp_rules_in_critical_section = [] | ||
important_rules_in_critical_section = [] | ||
file_patterns = [] | ||
dir_patterns = [] | ||
for line_num, line in enumerate(FileCache.readlines( | ||
|
@@ -2322,7 +2322,7 @@ def _check_codeowner_file(self): | |
# This is being populated for the important rules | ||
# check. | ||
if critical_file_section_found: | ||
imp_rules_in_critical_section.append( | ||
important_rules_in_critical_section.append( | ||
line_in_concern) | ||
# Checks if the path is the full path relative to the | ||
# root oppia directory. | ||
|
@@ -2381,8 +2381,9 @@ def _check_codeowner_file(self): | |
print '%s is not covered under CODEOWNERS' % file_path | ||
failed = True | ||
|
||
failed = self.check_for_important_rules_at_bottom_of_codeowners( | ||
imp_rules_in_critical_section, failed) | ||
failed = failed or ( | ||
self.check_for_important_rules_at_bottom_of_codeowners( | ||
important_rules_in_critical_section)) | ||
|
||
if failed: | ||
summary_message = '%s CODEOWNERS file check failed' % ( | ||
|
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".