From 9aa00dd302de4fbb7518dba0129d184682617bf0 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Mon, 19 Aug 2024 15:46:59 -0500 Subject: [PATCH] Add SetCurrentBranch class for set_current_branch function with JSON definition --- .../set_current_branch.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tools/github_tool_functions/set_current_branch.py diff --git a/tools/github_tool_functions/set_current_branch.py b/tools/github_tool_functions/set_current_branch.py new file mode 100644 index 0000000..f4460ae --- /dev/null +++ b/tools/github_tool_functions/set_current_branch.py @@ -0,0 +1,47 @@ +import logging + +class SetCurrentBranch: + def __init__(self, current_branch): + self.current_branch = current_branch + + # Set up logging + self.logger = logging.getLogger(__name__) + self.logger.setLevel(logging.INFO) + + # Create a file handler + file_handler = logging.FileHandler('set_current_branch.log') + file_handler.setLevel(logging.INFO) + + # Create a console handler + console_handler = logging.StreamHandler() + console_handler.setLevel(logging.INFO) + + # Create a formatting for the logs + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + file_handler.setFormatter(formatter) + console_handler.setFormatter(formatter) + + # Add the handlers to the logger + self.logger.addHandler(file_handler) + self.logger.addHandler(console_handler) + + def __call__(self, branch_name): + self.logger.info(f"Setting current branch from {self.current_branch} to {branch_name}") + self.current_branch = branch_name + return f"Current branch set to: {self.current_branch}" + +# JSON definition for the set_current_branch function +set_current_branch_definition = { + "name": "set_current_branch", + "description": "Set the current branch", + "parameters": { + "type": "object", + "properties": { + "branch_name": { + "type": "string", + "description": "Name of the branch to set as current" + } + }, + "required": ["branch_name"] + } +} \ No newline at end of file