-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sourcery refactored master branch #1
base: master
Are you sure you want to change the base?
Conversation
Hey! Changelogs info seems to be missing or might be in incorrect format. |
Authentication to CNP for DevOps failed. Click here to try again: https://portal.cwp.radwarecloud.com/github-plugin.html?installation_id=26169338&setup_action=install |
if 'override' in meta_dict: | ||
override = meta_dict['override'] | ||
for _, over_meta in override.items(): | ||
override_id = over_meta['id'] | ||
if 'platform' in over_meta: | ||
over_platform = over_meta['platform'] | ||
else: | ||
over_platform = platform | ||
if 'severity' in over_meta: | ||
over_severity = over_meta['severity'] | ||
else: | ||
over_severity = severity | ||
if 'category' in over_meta: | ||
over_category = over_meta['category'] | ||
else: | ||
over_category = category | ||
|
||
init_tree_path(template_dict, [ | ||
over_platform, sub_platform, over_severity, over_category]) | ||
|
||
template_dict[platform][sub_platform][severity][category][override_id] = copy.deepcopy( | ||
meta_dict) | ||
for key, value in over_meta.items(): | ||
template_dict[platform][sub_platform][severity][category][override_id][key] = value | ||
if 'override' not in meta_dict: | ||
return | ||
override = meta_dict['override'] | ||
for _, over_meta in override.items(): | ||
override_id = over_meta['id'] | ||
over_platform = over_meta['platform'] if 'platform' in over_meta else platform | ||
over_severity = over_meta['severity'] if 'severity' in over_meta else severity | ||
over_category = over_meta['category'] if 'category' in over_meta else category | ||
init_tree_path(template_dict, [ | ||
over_platform, sub_platform, over_severity, over_category]) | ||
|
||
template_dict[platform][sub_platform][severity][category][override_id] = copy.deepcopy( | ||
meta_dict) | ||
for key, value in over_meta.items(): | ||
template_dict[platform][sub_platform][severity][category][override_id][key] = value |
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.
Function check_and_create_override_entry
refactored with the following changes:
- Add guard clause (
last-if-guard
) - Replace if statement with if expression [×3] (
assign-if-exp
)
parsed_args['formats'] = ['.%s' % | ||
f.lstrip('.') for f in parsed_args['formats']] | ||
parsed_args['formats'] = [f".{f.lstrip('.')}" for f in parsed_args['formats']] |
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.
Lines 66-157
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Use f-string instead of string concatenation [×5] (
use-fstring-for-concatenation
)
if 'aggregation' in metadata_obj: | ||
rtn_count = metadata_obj['aggregation'] | ||
else: | ||
rtn_count = 1 | ||
rtn_count = metadata_obj['aggregation'] if 'aggregation' in metadata_obj else 1 |
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.
Function queries_count
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
platform_count = sum([queries_count(path) | ||
for path in glob.glob(metadata_path)]) | ||
platform_count = sum(queries_count(path) for path in glob.glob(metadata_path)) | ||
summary[f'{key}_queries'] = platform_count | ||
summary['total'] += platform_count | ||
|
||
rego_path = os.path.join(value, 'query.rego') | ||
rego_summary[f'{key}_rego'] = len([path for path in glob.glob(rego_path)]) | ||
rego_summary['total'] += len([path for path in glob.glob(rego_path)]) | ||
rego_summary[f'{key}_rego'] = len(list(glob.glob(rego_path))) | ||
rego_summary['total'] += len(list(glob.glob(rego_path))) | ||
|
||
for ext in samples_ext[key]: | ||
sample_path = os.path.join(value, 'test', f'*.{ext}') | ||
ext_samples = len([path for path in glob.glob(sample_path)]) | ||
ext_samples = len(list(glob.glob(sample_path))) |
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.
Lines 62-73
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
) - Replace identity comprehension with call to collection constructor [×3] (
identity-comprehension
)
print('Fetching PR #{} files... #page{}'.format(KICS_PR_NUMBER, page)) | ||
headers = {'Authorization': 'token {}'.format(KICS_GITHUB_TOKEN)} | ||
url = 'https://api.github.com/repos/checkmarx/kics/pulls/{}/files?per_page={}page={}'.format(KICS_PR_NUMBER, max_items, page) | ||
print(f'Fetching PR #{KICS_PR_NUMBER} files... #page{page}') | ||
headers = {'Authorization': f'token {KICS_GITHUB_TOKEN}'} | ||
url = f'https://api.github.com/repos/checkmarx/kics/pulls/{KICS_PR_NUMBER}/files?per_page={max_items}page={page}' | ||
|
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.
Function fetch
refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting
)
e2e_tests = len(files) - 1 | ||
|
||
return e2e_tests | ||
return len(files) - 1 |
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.
Function get_e2e_tests
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
platform_count = sum([queries_count(path) | ||
for path in glob.glob(metadata_path)]) | ||
platform_count = sum(queries_count(path) for path in glob.glob(metadata_path)) | ||
total_queries += platform_count | ||
|
||
for ext in samples_ext[key]: | ||
sample_path = os.path.join(value, 'test', f'*.{ext}') | ||
ext_samples = len([path for path in glob.glob(sample_path)]) | ||
ext_samples = len(list(glob.glob(sample_path))) |
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.
Function get_total_queries
refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator
) - Replace identity comprehension with call to collection constructor (
identity-comprehension
)
current_date = date.today().strftime("%Y/%m/%d") | ||
|
||
return current_date | ||
return date.today().strftime("%Y/%m/%d") |
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.
Function get_date
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
print('Opening file {}'.format(filename)) | ||
print(f'Opening file {filename}') | ||
with open(filename) as json_file: | ||
data = json.load(json_file) | ||
extract_command = re.search( | ||
'(\w+)-flags.json', filename, re.IGNORECASE) | ||
if not extract_command: | ||
return | ||
command = extract_command.group(1) | ||
command = extract_command[1] |
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.
Function get_json
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
data = {} | ||
data['added_commands'] = ', '.join(list(new_json.keys() - old_json.keys())) | ||
data = {'added_commands': ', '.join(list(new_json.keys() - old_json.keys()))} |
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.
Function prepare_template_data
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Convert for loop into list comprehension (
list-comprehension
)
if len(error_sending) > 0: | ||
if error_sending: |
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.
Lines 164-164
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
print('- Retrieving offset = {}'.format(offset)) | ||
response = requests.get('{}?limit=100&provider={}&offset={}&verified=true'.format(terraform_url, provider, str(offset))) | ||
print(f'- Retrieving offset = {offset}') | ||
response = requests.get( | ||
f'{terraform_url}?limit=100&provider={provider}&offset={str(offset)}&verified=true' | ||
) | ||
res_json = response.json() | ||
next_value = 'next_offset' in res_json['meta'] | ||
offset += 100 | ||
for module in res_json['modules']: | ||
modules_list.append({'id': module['id'], 'name': module['name']}) | ||
|
||
modules_list.extend({ | ||
'id': module['id'], | ||
'name': module['name'] | ||
} for module in res_json['modules']) | ||
print('{separator} Finished Getting Modules {separator}'.format(separator=separator)) | ||
print('\n{separator} Getting Modules Infos {separator}'.format(separator=separator)) | ||
module_info_dict = {} | ||
for module in modules_list: | ||
print('- Retrieving module = {}'.format(module['id'])) | ||
response = requests.get('{}/{}'.format(terraform_url, module['id'])) | ||
print(f"- Retrieving module = {module['id']}") | ||
response = requests.get(f"{terraform_url}/{module['id']}") |
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.
Lines 58-171
refactored with the following changes:
- Replace call to format with f-string [×10] (
use-fstring-for-formatting
) - Replace a for append loop with list extend (
for-append-to-extend
) - Convert for loop into dictionary comprehension (
dict-comprehension
) - Use items() to directly unpack dictionary values (
use-dict-items
) - Simplify sequence length comparison (
simplify-len-comparison
) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
This removes the following comments ( why? ):
# flatten list process
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.20%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!