From dc1a8e8314fb46fa745ed67b1139f8c76e7dd44a Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 18 Aug 2024 08:13:40 +0300 Subject: [PATCH] Add detailed logging and error handling in GitHub polling server - Introduce traceback logging for exceptions during notification processing. - Enhance logging for PR comments with additional artifact information. - Update configuration settings for publishing PR descriptions as comments. --- pr_agent/servers/github_polling.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pr_agent/servers/github_polling.py b/pr_agent/servers/github_polling.py index a0e875bc..627390c0 100644 --- a/pr_agent/servers/github_polling.py +++ b/pr_agent/servers/github_polling.py @@ -1,4 +1,5 @@ import asyncio +import traceback from datetime import datetime, timezone import aiohttp @@ -15,7 +16,7 @@ NOTIFICATION_URL = "https://api.github.com/notifications" def now() -> str: """ Get the current UTC time in ISO 8601 format. - + Returns: str: The current UTC time in ISO 8601 format. """ @@ -35,6 +36,7 @@ async def polling_loop(): user_id = git_provider.get_user_id() agent = PRAgent() get_settings().set("CONFIG.PUBLISH_OUTPUT_PROGRESS", False) + get_settings().set("pr_description.publish_description_as_comment", True) try: deployment_type = get_settings().github.deployment_type @@ -92,7 +94,8 @@ async def polling_loop(): comment_body = comment['body'] if 'body' in comment else '' commenter_github_user = comment['user']['login'] \ if 'user' in comment else '' - get_logger().info(f"Commenter: {commenter_github_user}\nComment: {comment_body}") + get_logger().info(f"Polling, pr_url: {pr_url}", + artifact={"comment": comment_body}) user_tag = "@" + user_id if user_tag not in comment_body: continue @@ -100,7 +103,8 @@ async def polling_loop(): comment_id = comment['id'] git_provider.set_pr(pr_url) success = await agent.handle_request(pr_url, rest_of_comment, - notify=lambda: git_provider.add_eyes_reaction(comment_id)) # noqa E501 + notify=lambda: git_provider.add_eyes_reaction( + comment_id)) # noqa E501 if not success: git_provider.set_pr(pr_url) @@ -108,7 +112,8 @@ async def polling_loop(): print(f"Failed to fetch notifications. Status code: {response.status}") except Exception as e: - get_logger().error(f"Exception during processing of a notification: {e}") + get_logger().error(f"Polling exception during processing of a notification: {e}", + artifact={"traceback": traceback.format_exc()}) if __name__ == '__main__':