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

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 24, 2022

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:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from 1989shack June 24, 2022 12:40
@changelogg
Copy link

changelogg bot commented Jun 24, 2022

Hey! Changelogs info seems to be missing or might be in incorrect format.
Please use the below template in PR description to ensure Changelogg can detect your changes:
- (tag) changelog_text
or
- tag: changelog_text
OR
You can add tag in PR header or while doing a commit too
(tag) PR header
or
tag: PR header
Valid tags: added / feat, changed, deprecated, fixed / fix, removed, security, build, ci, chore, docs, perf, refactor, revert, style, test
Thanks!
For more info, check out changelogg docs

@cnp-for-devops
Copy link

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

Comment on lines -29 to +43
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
Copy link
Author

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:

Comment on lines -66 to +57
parsed_args['formats'] = ['.%s' %
f.lstrip('.') for f in parsed_args['formats']]
parsed_args['formats'] = [f".{f.lstrip('.')}" for f in parsed_args['formats']]
Copy link
Author

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:

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
Copy link
Author

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:

Comment on lines -62 to +69
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)))
Copy link
Author

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:

Comment on lines -21 to +24
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}'

Copy link
Author

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:

Comment on lines -101 to +108
e2e_tests = len(files) - 1

return e2e_tests
return len(files) - 1
Copy link
Author

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:

Comment on lines -110 to +120
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)))
Copy link
Author

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:

Comment on lines -131 to +135
current_date = date.today().strftime("%Y/%m/%d")

return current_date
return date.today().strftime("%Y/%m/%d")
Copy link
Author

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:

Comment on lines -15 to +22
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]
Copy link
Author

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:

data = {}
data['added_commands'] = ', '.join(list(new_json.keys() - old_json.keys()))
data = {'added_commands': ', '.join(list(new_json.keys() - old_json.keys()))}
Copy link
Author

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:

if len(error_sending) > 0:
if error_sending:
Copy link
Author

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:

Comment on lines -58 to +74
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']}")
Copy link
Author

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:

This removes the following comments ( why? ):

# flatten list process

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jun 24, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.20%.

Quality metrics Before After Change
Complexity 14.67 🙂 13.62 🙂 -1.05 👍
Method Length 81.82 🙂 81.11 🙂 -0.71 👍
Working memory 8.97 🙂 9.07 🙂 0.10 👎
Quality 55.31% 🙂 55.51% 🙂 0.20% 👍
Other metrics Before After Change
Lines 1050 1053 3
Changed files Quality Before Quality After Quality Change
.github/scripts/docs-generator/docs-generator.py 37.56% 😞 38.26% 😞 0.70% 👍
.github/scripts/metrics/get_metrics.py 64.20% 🙂 63.41% 🙂 -0.79% 👎
.github/scripts/queries-validator/queries-validator.py 79.92% ⭐ 81.47% ⭐ 1.55% 👍
.github/scripts/release-commits/get_commits.py 77.50% ⭐ 76.14% ⭐ -1.36% 👎
.github/scripts/samples-linters/validate-syntax.py 65.18% 🙂 66.36% 🙂 1.18% 👍
.github/scripts/statistics/get_statistics.py 75.18% ⭐ 74.87% 🙂 -0.31% 👎
.github/scripts/watchers/change-flags-email.py 51.83% 🙂 53.41% 🙂 1.58% 👍
.github/scripts/watchers/terraform-modules-update.py 21.28% ⛔ 21.15% ⛔ -0.13% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
.github/scripts/watchers/change-flags-email.py prepare_template_data 15 🙂 308 ⛔ 11 😞 37.00% 😞 Try splitting into smaller methods. Extract out complex expressions
.github/scripts/samples-linters/validate-syntax.py main 23 😞 164 😞 8 🙂 45.84% 😞 Refactor to reduce nesting. Try splitting into smaller methods
.github/scripts/samples-linters/validate-syntax.py run_linter 9 🙂 133 😞 10 😞 56.03% 🙂 Try splitting into smaller methods. Extract out complex expressions
.github/scripts/statistics/get_statistics.py get_relevant_issues_info 6 ⭐ 106 🙂 12 😞 58.63% 🙂 Extract out complex expressions
.github/scripts/docs-generator/docs-generator.py check_and_create_override_entry 10 🙂 104 🙂 10 😞 58.75% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

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.

0 participants