Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/natzar/ai-developer into main
Browse files Browse the repository at this point in the history
# Conflicts:
#	ai_developer/task_handler.py
  • Loading branch information
AI committed Dec 30, 2023
2 parents 71f9548 + b0506f7 commit 79f793e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 deletions.
20 changes: 15 additions & 5 deletions ai_developer/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,28 +191,35 @@ def git_pull(sandbox: Sandbox, args: Dict[str, Any]) -> str:
except Exception as e:
return f"Error: {e}"


def git_reset(sandbox: Sandbox, args: Dict[str, Any]) -> str:
repo_directory = "/home/user/repo"
working_branch = args.get("working_branch", "main")
print_sandbox_action("Resetting repo to branch in origin", working_branch)

try:
# Fetch the latest changes from origin
git_fetch_proc = sandbox.process.start_and_wait(f"git -C {repo_directory} fetch origin")
git_fetch_proc = sandbox.process.start_and_wait(
f"git -C {repo_directory} fetch origin"
)
if git_fetch_proc.exit_code != 0:
error = f"Error fetching from origin: {git_fetch_proc.stdout}\n\t{git_fetch_proc.stderr}"
console.print("\t[bold red]Error:[/bold red]", error)
return error

# Reset the local branch to match the origin branch
git_reset_proc = sandbox.process.start_and_wait(f"git -C {repo_directory} reset --hard origin/{working_branch}")
git_reset_proc = sandbox.process.start_and_wait(
f"git -C {repo_directory} reset --hard origin/{working_branch}"
)
if git_reset_proc.exit_code != 0:
error = f"Error resetting branch '{working_branch}': {git_reset_proc.stdout}\n\t{git_reset_proc.stderr}"
console.print("\t[bold red]Error:[/bold red]", error)
return error

# Clean up any untracked files
git_clean_proc = sandbox.process.start_and_wait(f"git -C {repo_directory} clean -fd")
git_clean_proc = sandbox.process.start_and_wait(
f"git -C {repo_directory} clean -fd"
)
if git_clean_proc.exit_code != 0:
error = f"Error cleaning untracked files: {git_clean_proc.stdout}\n\t{git_clean_proc.stderr}"
console.print("\t[bold red]Error:[/bold red]", error)
Expand All @@ -222,11 +229,12 @@ def git_reset(sandbox: Sandbox, args: Dict[str, Any]) -> str:
except Exception as e:
return f"Error: {e}"


def execute_pylint(sandbox: Sandbox, args: Dict[str, Any]) -> str:
path = args.get("path", REPO_DIRECTORY)
print_sandbox_action("Running pylint on", path)

pylint_cmd = f'pylint {path}'
pylint_cmd = f"pylint {path}"
pylint_proc = sandbox.process.start_and_wait(pylint_cmd)
if pylint_proc.exit_code != 0:
error = pylint_proc.stderr.strip()
Expand All @@ -235,7 +243,9 @@ def execute_pylint(sandbox: Sandbox, args: Dict[str, Any]) -> str:

output = pylint_proc.stdout.strip()
console.print("[bold green]Pylint Output:[/bold green]\n", output)
return output
return output


# Ideas for new actions:
# - Automated code formatting checks
# - Security vulnerability scanning
Expand Down
42 changes: 21 additions & 21 deletions ai_developer/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,26 @@ def create_assistant():
"required": ["title"],
},
},
},
{
"type": "function",
"function": {
"name": "git_reset",
"description": "Reset a repo to match a remote origin branch.",
"parameters": {
"type": "object",
"properties": {
"working_branch": {
"type": "string",
"description": "The name of the branch to reset to. Defaults to 'main'.",
"default": "main"
}
},
"required": []
}
}
},
{
},
{
"type": "function",
"function": {
"name": "git_reset",
"description": "Reset a repo to match a remote origin branch.",
"parameters": {
"type": "object",
"properties": {
"working_branch": {
"type": "string",
"description": "The name of the branch to reset to. Defaults to 'main'.",
"default": "main",
}
},
"required": [],
},
},
},
{
"type": "function",
"function": {
"name": "execute_pylint",
Expand All @@ -184,7 +184,7 @@ def create_assistant():
"path": {
"type": "string",
"description": "The path to the directory or file to run pylint on, defaults to REPO_DIRECTORY",
"default": "REPO_DIRECTORY"
"default": "REPO_DIRECTORY",
}
},
"required": [],
Expand Down
8 changes: 6 additions & 2 deletions ai_developer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
REPO_DIRECTORY,
git_pull,
git_reset,
execute_pylint
execute_pylint,
)

# Defaults
Expand Down Expand Up @@ -175,7 +175,11 @@ def main():
make_pull_request
).add_action(
git_pull
).add_action(git_reset).add_action(execute_pylint)
).add_action(
git_reset
).add_action(
execute_pylint
)

# Setup git right away so user knows immediatelly if they passed wrong
# token
Expand Down
1 change: 0 additions & 1 deletion ai_developer/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ def apply_filters(self, hook_name: str, value, *args) -> Any:
for function in self.filters[hook_name]:
value = function(value, *args)
return value

2 changes: 1 addition & 1 deletion ai_developer/task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, client, sandbox, assistant, console):
self.sandbox = sandbox
self.console = console
self.assistant = assistant
plugin_system.do_action('init_task_handler', self)
# plugin_system.do_action("init_task_handler", self)

def handle_new_task(self, user_task, repo_url):
thread_id = self.create_thread(user_task, repo_url)
Expand Down

0 comments on commit 79f793e

Please sign in to comment.