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

Fix: Case insensitive reviewers comparison + pip-audit #763

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions local-dev/pip-audit-parse.py
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()
5 changes: 5 additions & 0 deletions local-dev/pip-audit.sh
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def setup_argparser() -> argparse.ArgumentParser:
return parser


def generate_and_save_basic_template( # pylint: disable=too-many-arguments
def generate_and_save_basic_template( # pylint: disable=too-many-arguments,too-many-positional-arguments
template_path: str,
package: str,
default_channel: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class OperatorReview:
A class represents a pull request review and permissions check
"""

def __init__( # pylint: disable=too-many-arguments
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments
self,
operator: Operator,
pr_owner: str,
Expand Down Expand Up @@ -143,9 +143,14 @@ def reviewers(self) -> list[str]:
Operator reviewers from the operator config file

Returns:
list[str]: A list of github users who are reviewers for the operator
list[str]: A list of github users who are reviewers for the
operator in lowercase format
"""
return self.base_repo_operator_config.get("reviewers") or []
reviewers = self.base_repo_operator_config.get("reviewers") or []
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 👍


# Github supports case-insensitive usernames - convert all usernames to lowercase
# to avoid issues with case sensitivity
return [user.lower() for user in reviewers]

@property
def maintainers(self) -> list[str]:
Expand Down Expand Up @@ -300,7 +305,7 @@ def check_permission_for_community(self) -> bool:
"or is brand new."
)

if self.pr_owner in self.reviewers:
if self.pr_owner.lower() in self.reviewers:
LOGGER.info(
"Pull request owner %s can submit PR for operator %s",
self.pr_owner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def setup_argparser() -> Any: # pragma: no cover
return parser


def open_pr( # pylint: disable=too-many-arguments
def open_pr( # pylint: disable=too-many-arguments,too-many-positional-arguments
github_api_url: str,
repo_name: str,
head: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setup_argparser() -> argparse.ArgumentParser:
return parser


def execute_checks( # pylint: disable=too-many-arguments
def execute_checks( # pylint: disable=too-many-arguments,too-many-positional-arguments
repo_path: str,
operator_name: str,
bundle_version: str,
Expand Down
2 changes: 1 addition & 1 deletion operator-pipeline-images/operatorcert/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def add_or_remove_labels( # pylint: disable=too-many-locals
remove_labels_from_pull_request(pull_request, labels_to_remove)


def open_pull_request( # pylint: disable=too-many-arguments
def open_pull_request( # pylint: disable=too-many-arguments,too-many-positional-arguments
github_client: Github,
repository_name: str,
title: str,
Expand Down
2 changes: 1 addition & 1 deletion operator-pipeline-images/operatorcert/parsed_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ParserResults:
Data class to store the results of the detect_changes function
"""

def __init__( # pylint: disable=too-many-arguments
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments
self,
affected_operators: AffectedOperatorCollection,
affected_bundles: AffectedBundleCollection,
Expand Down
2 changes: 1 addition & 1 deletion operator-pipeline-images/operatorcert/umb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UmbClient:
A UMB client for sending and receiving messages from the UMB.
"""

def __init__( # pylint: disable=too-many-arguments
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments
self,
hostnames: List[tuple[str, int]],
cert_file: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def review_community(tmp_path: Path) -> check_permissions.OperatorReview:
"0.0.1",
other_files={
"operators/test-operator/ci.yaml": {
"reviewers": ["user1", "user2"],
"reviewers": ["User1", "user2"],
},
"config.yaml": {"maintainers": ["maintainer1", "maintainer2"]},
},
Expand Down
Loading
Loading