fix: Logging and Commenting

This commit is contained in:
ishaansehgal99
2025-03-20 13:55:07 -07:00
parent 737cf559d9
commit bc575e5a67

View File

@ -233,7 +233,7 @@ def get_log_context(body, event, action, build_number):
"request_id": uuid.uuid4().hex, "build_number": build_number, "app_name": app_name, "request_id": uuid.uuid4().hex, "build_number": build_number, "app_name": app_name,
"repo": repo, "git_org": git_org, "installation_id": installation_id} "repo": repo, "git_org": git_org, "installation_id": installation_id}
except Exception as e: except Exception as e:
get_logger().error("Failed to get log context", e) get_logger().error(f"Error parsing request body: {e}")
log_context = {} log_context = {}
return log_context, sender, sender_id, sender_type return log_context, sender, sender_id, sender_type
@ -310,16 +310,20 @@ async def handle_request(body: Dict[str, Any], event: str):
event: The GitHub event type (e.g. "pull_request", "issue_comment", etc.). event: The GitHub event type (e.g. "pull_request", "issue_comment", etc.).
""" """
action = body.get("action") # "created", "opened", "reopened", "ready_for_review", "review_requested", "synchronize" action = body.get("action") # "created", "opened", "reopened", "ready_for_review", "review_requested", "synchronize"
get_logger().debug(f"Handling request with event: {event}, action: {action}")
if not action: if not action:
get_logger().debug(f"No action found in request body, exiting handle_request")
return {} return {}
agent = PRAgent() agent = PRAgent()
log_context, sender, sender_id, sender_type = get_log_context(body, event, action, build_number) log_context, sender, sender_id, sender_type = get_log_context(body, event, action, build_number)
# logic to ignore PRs opened by bot, PRs with specific titles, labels, source branches, or target branches # logic to ignore PRs opened by bot, PRs with specific titles, labels, source branches, or target branches
if is_bot_user(sender, sender_type) and 'check_run' not in body: if is_bot_user(sender, sender_type) and 'check_run' not in body:
get_logger().debug(f"Request ignored: bot user detected")
return {} return {}
if action != 'created' and 'check_run' not in body: if action != 'created' and 'check_run' not in body:
if not should_process_pr_logic(body): if not should_process_pr_logic(body):
get_logger().debug(f"Request ignored: PR logic filtering")
return {} return {}
if 'check_run' in body: # handle failed checks if 'check_run' in body: # handle failed checks