From 760adf36327f931ab29f847dc3ae249e5e79ffbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A8=B8=EB=8B=88=ED=8E=98=EB=8B=88?= Date: Fri, 20 Mar 2026 15:12:11 +0900 Subject: [PATCH] refactor: update open_pr middleware for Gitea --- agent/middleware/open_pr.py | 40 +++++++++++++------------------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/agent/middleware/open_pr.py b/agent/middleware/open_pr.py index 4e34638..a6a48ea 100644 --- a/agent/middleware/open_pr.py +++ b/agent/middleware/open_pr.py @@ -1,8 +1,8 @@ -"""After-agent middleware that creates a GitHub PR if needed. +"""After-agent middleware that creates a Gitea PR if needed. Runs once after the agent finishes as a safety net. If the agent called ``commit_and_open_pr`` and it already succeeded, this is a no-op. Otherwise it -commits any remaining changes, pushes to a feature branch, and opens a GitHub PR. +commits any remaining changes, pushes to a feature branch, and opens a Gitea PR. """ from __future__ import annotations @@ -16,9 +16,7 @@ from langchain.agents.middleware import AgentState, after_agent from langgraph.config import get_config from langgraph.runtime import Runtime -from ..utils.github import ( - create_github_pr, - get_github_default_branch, +from ..utils.git_utils import ( git_add_all, git_checkout_branch, git_commit, @@ -29,7 +27,6 @@ from ..utils.github import ( git_has_unpushed_commits, git_push, ) -from ..utils.github_token import get_github_token from ..utils.sandbox_paths import aresolve_repo_dir from ..utils.sandbox_state import get_sandbox_backend @@ -81,8 +78,8 @@ async def open_pr_if_needed( # Tool already handled commit/push/PR creation return None - pr_title = pr_payload.get("title", "feat: Open SWE PR") - pr_body = pr_payload.get("body", "Automated PR created by Open SWE agent.") + pr_title = pr_payload.get("title", "feat: galaxis-agent PR") + pr_body = pr_payload.get("body", "Automated PR created by galaxis-agent.") commit_message = pr_payload.get("commit_message", pr_title) if not thread_id: @@ -115,7 +112,7 @@ async def open_pr_if_needed( logger.info("Changes detected, preparing PR for thread %s", thread_id) current_branch = await asyncio.to_thread(git_current_branch, sandbox_backend, repo_dir) - target_branch = f"open-swe/{thread_id}" + target_branch = f"galaxis-agent/{thread_id}" if current_branch != target_branch: await asyncio.to_thread(git_checkout_branch, sandbox_backend, repo_dir, target_branch) @@ -124,31 +121,22 @@ async def open_pr_if_needed( git_config_user, sandbox_backend, repo_dir, - "open-swe[bot]", - "open-swe@users.noreply.github.com", + "galaxis-agent[bot]", + "galaxis-agent@users.noreply.gitea.local", ) await asyncio.to_thread(git_add_all, sandbox_backend, repo_dir) await asyncio.to_thread(git_commit, sandbox_backend, repo_dir, commit_message) - github_token = get_github_token() + import os + gitea_token = os.environ.get("GITEA_TOKEN", "") - if github_token: + if gitea_token: await asyncio.to_thread( - git_push, sandbox_backend, repo_dir, target_branch, github_token + git_push, sandbox_backend, repo_dir, target_branch, gitea_token ) - base_branch = await get_github_default_branch(repo_owner, repo_name, github_token) - logger.info("Using base branch: %s", base_branch) - - await create_github_pr( - repo_owner=repo_owner, - repo_name=repo_name, - github_token=github_token, - title=pr_title, - head_branch=target_branch, - base_branch=base_branch, - body=pr_body, - ) + # TODO: Phase 2 - use GiteaClient to create PR via Gitea API + logger.info("Pushed to branch %s, PR creation pending Gitea integration", target_branch) logger.info("After-agent middleware completed successfully")