From b45c4f5071a7c0302c51736a015ac3952188b5fb Mon Sep 17 00:00:00 2001 From: Christine Wang Date: Wed, 12 Feb 2025 17:27:16 -0800 Subject: [PATCH] fix: create PR tool checks out onto custom branch (#470) --- src/codegen/extensions/langchain/tools.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/codegen/extensions/langchain/tools.py b/src/codegen/extensions/langchain/tools.py index 144762b71..00a6365e9 100644 --- a/src/codegen/extensions/langchain/tools.py +++ b/src/codegen/extensions/langchain/tools.py @@ -1,6 +1,7 @@ """Langchain tools for workspace operations.""" import json +import uuid from typing import ClassVar, Literal, Optional from langchain.tools import BaseTool @@ -355,6 +356,9 @@ def __init__(self, codebase: Codebase) -> None: super().__init__(codebase=codebase) def _run(self, title: str, body: str) -> str: + if self.codebase._op.git_cli.active_branch.name == self.codebase._op.default_branch: + # If the current checked out branch is the default branch, checkout onto a new branch + self.codebase.checkout(branch=f"{uuid.uuid4()}", create_if_missing=True) pr = self.codebase.create_pr(title=title, body=body) return pr.html_url