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 KeyError: 'owner' in handle_check_run() #352

Merged
merged 1 commit into from
Oct 27, 2024
Merged
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
19 changes: 15 additions & 4 deletions services/check_run_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Local imports
import json
from config import GITHUB_APP_USER_NAME, STRIPE_PRODUCT_ID_FREE, SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY
from config import (
GITHUB_APP_USER_NAME,
STRIPE_PRODUCT_ID_FREE,
SUPABASE_URL,
SUPABASE_SERVICE_ROLE_KEY,
)
from services.github.actions_manager import get_workflow_run_logs, get_workflow_run_path
from services.github.github_manager import (
get_installation_access_token,
Expand All @@ -14,6 +19,7 @@
CheckRun,
CheckRunCompletedPayload,
CheckSuite,
Owner,
PullRequest,
Repository,
)
Expand Down Expand Up @@ -43,9 +49,14 @@ def handle_check_run(payload: CheckRunCompletedPayload) -> None:
is_fork: bool = repo.get("fork", False)

# Extract owner related variables
owner_type: str = repo["owner"]["type"]
owner_id: int = repo["owner"]["id"]
owner_name: str = repo["owner"]["login"]
owner: Owner = repo.get("owner", {})
if owner is None:
msg = "Skipping because owner is not found"
print(colorize(text=msg, color="yellow"))
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider using a logging framework instead of print for operational events

In a service handler, it's better to use proper logging for operational events rather than print statements. This would help with monitoring and debugging in production.

        logging.warning(msg)

return
owner_type: str = owner["type"]
owner_id: int = owner["id"]
owner_name: str = owner["login"]

# Extract branch related variables
check_suite: CheckSuite = check_run["check_suite"]
Expand Down