فهرست منبع

randomize branch names (#5784)

Robert Brennan 1 سال پیش
والد
کامیت
642e962f89
2فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 1 1
      openhands/agenthub/codeact_agent/micro/github.md
  2. 8 1
      openhands/runtime/base.py

+ 1 - 1
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.

+ 8 - 1
openhands/runtime/base.py

@@ -2,6 +2,8 @@ import atexit
 import copy
 import json
 import os
+import random
+import string
 from abc import abstractmethod
 from pathlib import Path
 from typing import Callable
@@ -203,8 +205,13 @@ class Runtime(FileEditRuntimeMixin):
             return
         url = 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)