mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-02 11:50:37 +08:00
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.
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user