Sourcery Starbot ⭐ refactored vbrozik/fortigate2csv#2
Open
SourceryAI wants to merge 1 commit intovbrozik:masterfrom
Open
Sourcery Starbot ⭐ refactored vbrozik/fortigate2csv#2SourceryAI wants to merge 1 commit intovbrozik:masterfrom
SourceryAI wants to merge 1 commit intovbrozik:masterfrom
Conversation
SourceryAI
commented
May 10, 2022
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]) |
Author
There was a problem hiding this comment.
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
masterbranch, then run: