Skip to content

Commit

Permalink
randomize branch names (#5784)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren authored Dec 24, 2024
1 parent d4e670a commit 642e962
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion openhands/agenthub/codeact_agent/micro/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion openhands/runtime/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import copy
import json
import os
import random
import string
from abc import abstractmethod
from pathlib import Path
from typing import Callable
Expand Down Expand Up @@ -203,8 +205,13 @@ def clone_repo(self, github_token: str | None, selected_repository: str | None):
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)
Expand Down

0 comments on commit 642e962

Please sign in to comment.