Add SetCurrentBranch class for set_current_branch function with JSON definition
This commit is contained in:
@@ -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"]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user