π OpenHands: AI-Driven Development
randomize branch names (#5784)
Robert Brennan642e962f89c4
diff --git a/openhands/agenthub/codeact_agent/micro/github.md b/openhands/agenthub/codeact_agent/micro/github.mdindex c03bb546cd..00afa6c1bd 100644--- a/openhands/agenthub/codeact_agent/micro/github.md+++ b/openhands/agenthub/codeact_agent/micro/github.md@@ -15,7 +15,7 @@ ALWAYS use the GitHub API for operations instead of a web browser.Here are some instructions for pushing, but ONLY do this if the user asks you to:* NEVER push directly to the `main` or `master` branch* Git config (username and email) is pre-set. Do not modify.-* You may already be on a branch called `openhands-workspace`. Create a new branch with a better name before pushing.+* You may already be on a branch starting with `openhands-workspace`. Create a new branch with a better name before pushing.* Use the GitHub API to create a pull request, if you haven't already* Use the main branch as the base branch, unless the user requests otherwise* After opening or updating a pull request, send the user a short message with a link to the pull request.diff --git a/openhands/runtime/base.py b/openhands/runtime/base.pyindex 1dcafdcb75..69ece77a30 100644--- a/openhands/runtime/base.py+++ b/openhands/runtime/base.py@@ -2,6 +2,8 @@ import atexitimport copyimport jsonimport os+import random+import stringfrom abc import abstractmethodfrom pathlib import Pathfrom typing import Callable@@ -203,8 +205,13 @@ class Runtime(FileEditRuntimeMixin):returnurl = f'https://{github_token}@github.com/{selected_repository}.git'dir_name = selected_repository.split('/')[1]+ # add random branch name to avoid conflicts+ random_str = ''.join(+ random.choices(string.ascii_lowercase + string.digits, k=8)+ )+ branch_name = f'openhands-workspace-{random_str}'action = CmdRunAction(- command=f'git clone {url} {dir_name} ; cd {dir_name} ; git checkout -b openhands-workspace'+ command=f'git clone {url} {dir_name} ; cd {dir_name} ; git checkout -b {branch_name}',)self.log('info', f'Cloning repo: {selected_repository}')self.run_action(action)