-
Notifications
You must be signed in to change notification settings - Fork 62
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
Fix: Case insensitive reviewers comparison + pip-audit #763
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python3 | ||
import json | ||
import argparse | ||
from typing import Dict, Any | ||
|
||
from rich.table import Table | ||
from rich.console import Console | ||
|
||
|
||
def parse_vulnerabilities_json(data: Dict[str, Any]) -> bool: | ||
""" | ||
Parses pip-audit json output, extracts fixable vulnerabilities | ||
and pretty prints them. | ||
""" | ||
|
||
vulnerable_packages = [] | ||
for package in data.get("dependencies", {}): | ||
name = package.get("name") | ||
vulnerabilities = package.get("vulns", []) | ||
version = package.get("version") | ||
if not vulnerabilities: | ||
print(f"✅ {name} {version}") | ||
else: | ||
has_fixable_vulnerabilities = False | ||
for vulnerability in vulnerabilities: | ||
# filter out vulnerabilities that cannot be fixed | ||
if fix := vulnerability.get("fix_versions", []) or None: | ||
vulnerable_packages.append( | ||
{ | ||
"name": name, | ||
"version": version, | ||
"vulnerability": vulnerability.get("id"), | ||
"fix": fix, | ||
} | ||
) | ||
has_fixable_vulnerabilities = True | ||
if has_fixable_vulnerabilities: | ||
print(f"❌ {name} {version}") | ||
else: | ||
print(f"❗ {name} {version}") | ||
|
||
if vulnerable_packages: | ||
print("Vulnerable packages found:") | ||
table = Table("Package", "Version", "Vulnerability", "Fixed version") | ||
to_update = [] | ||
for package in vulnerable_packages: | ||
table.add_row( | ||
package["name"], | ||
package["version"], | ||
package["vulnerability"], | ||
",".join(package["fix"]), | ||
) | ||
to_update.append(package["name"]) | ||
console = Console() | ||
console.print(table) | ||
print(f"To fix, run:\npdm update {' '.join(to_update)} --update-reuse") | ||
return False | ||
return True | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser(description="Process a JSON file.") | ||
parser.add_argument("filename", help="The JSON file to process") | ||
|
||
args = parser.parse_args() | ||
with open(args.filename, "r") as file: | ||
data = json.load(file) | ||
|
||
if not parse_vulnerabilities_json(data): | ||
exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
# remove any previous runs to ensure isolated run | ||
rm -f /tmp/audit-output.json | ||
# run pip-audit on dependencies, output to json file, mask any failures | ||
pip-audit -r /tmp/requirements.txt --format=json -o /tmp/audit-output.json || true |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
I am wondering if maybe we want to also make this change for the property
maintainers
? But It seems that maintainers not being unified to lowercase don't break anything, so this is just a thought.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.
I was initially also thinking about it but then I rejected the idea because we control the list of maintainers (we can edit it anytime) and it is not used the same way as the list of reviewers.
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.
Good argument. Feel free to disregard my comment and merge as-is 👍