-
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 Starbot ⭐ refactored vbrozik/fortigate2csv #2
base: master
Are you sure you want to change the base?
Conversation
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]) |
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 build_csv
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Hoist for/while loops out of nested conditionals (
hoist-loop-from-if
)
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 Code Quality Report✅ Merging this PR will increase code quality in the affected files by 1.26%.
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! |
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: