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 Starbot ⭐ refactored vbrozik/fortigate2csv #2

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

Conversation

SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/fortigate2csv master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines -278 to +297
if (
header == "ipv4_addresses"
): # parse list, extract ip mask for each item within the field
for x in row[header]:
for x in row[header]:
if (
header == "ipv4_addresses"
): # parse list, extract ip mask for each item within the field
subitems.append(f"{x['ip']}/{x['cidr_netmask']}")
else: # parse list, extract q_origin_key for each item within the field
for x in row[header]:
if (
elif (
address_lookup
and x["q_origin_key"] in address_lookup
):
subitems.append(address_lookup[x["q_origin_key"]])
else:
subitems.append(x["q_origin_key"])
subitems.append(address_lookup[x["q_origin_key"]])
else:
subitems.append(x["q_origin_key"])
# join with a space, can't use comma due to csv
row_data.append(" ".join(map(str, subitems)))
elif type(row[header]) == str:
row_data.append(row[header].replace(",", ""))
elif address_lookup and row[header] in address_lookup:
subitems.append(address_lookup[row[header]])
else:
# this field is just a string/int, simply add it to the row
if type(row[header]) == str:
row_data.append(row[header].replace(",", ""))
else:
if address_lookup and row[header] in address_lookup:
subitems.append(address_lookup[row[header]])
else:
row_data.append(row[header])
row_data.append(row[header])
Copy link
Author

Choose a reason for hiding this comment

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

Function build_csv refactored with the following changes:

This removes the following comments ( why? ):

# parse list, extract q_origin_key for each item within the field
# this field is just a string/int, simply add it to the row

@sourcery-ai
Copy link

sourcery-ai bot commented May 10, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 32.23 😞 25.80 😞 -6.43 👍
Method Length 202.00 😞 201.00 😞 -1.00 👍
Working memory 15.19 ⛔ 15.27 ⛔ 0.08 👎
Quality 26.79% 😞 28.05% 😞 1.26% 👍
Other metrics Before After Change
Lines 351 346 -5
Changed files Quality Before Quality After Quality Change
fortigate2csv.py 26.79% 😞 28.05% 😞 1.26% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
fortigate2csv.py main 29 😞 662 ⛔ 18 ⛔ 15.60% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
fortigate2csv.py build_csv 37 ⛔ 177 😞 13 😞 28.29% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
fortigate2csv.py f_login 5 ⭐ 124 😞 11 😞 59.03% 🙂 Try splitting into smaller methods. 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.

1 participant