From 69a7c77a0d8762c6eb14285138040c42fca493d6 Mon Sep 17 00:00:00 2001 From: Brian Pham Date: Thu, 14 Dec 2023 07:15:56 +0800 Subject: [PATCH] Refactor PRAgent class and has_ai_handler_param method This commit refactors the PRAgent class and the has_ai_handler_param method. The has_ai_handler_param method is moved outside the class and made a standalone function. This change improves code organization and readability. The has_ai_handler_param function now takes a class object as a parameter and checks if the class constructor has an "ai_handler" parameter. This refactoring is done to streamline the code and improve its maintainability. No issue references. --- pr_agent/agent/pr_agent.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pr_agent/agent/pr_agent.py b/pr_agent/agent/pr_agent.py index 5c6e4ec1..ff2237e0 100644 --- a/pr_agent/agent/pr_agent.py +++ b/pr_agent/agent/pr_agent.py @@ -38,17 +38,18 @@ command2class = { commands = list(command2class.keys()) +def has_ai_handler_param(cls: object): + constructor = getattr(cls, "__init__", None) + if constructor is not None: + parameters = inspect.signature(constructor).parameters + return "ai_handler" in parameters + return False + class PRAgent: def __init__(self, ai_handler: BaseAiHandler = None): self.ai_handler = ai_handler pass - def has_ai_handler_param(cls: object): - constructor = getattr(cls, "__init__", None) - if constructor is not None: - parameters = inspect.signature(constructor).parameters - return "ai_handler" in parameters - return False async def handle_request(self, pr_url, request, notify=None) -> bool: # First, apply repo specific settings if exists @@ -75,7 +76,7 @@ class PRAgent: notify() get_logger().info(f"Class: {command2class[action]}") - if(not self.has_ai_handler_param(cls=command2class[action])): + if(not has_ai_handler_param(cls=command2class[action])): await command2class[action](pr_url, args=args).run() else: await command2class[action](pr_url, ai_handler=self.ai_handler, args=args).run()