refactor: update open_pr middleware for Gitea
This commit is contained in:
parent
4f2cb5bd1e
commit
760adf3632
@ -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
|
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
|
``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
|
from __future__ import annotations
|
||||||
@ -16,9 +16,7 @@ from langchain.agents.middleware import AgentState, after_agent
|
|||||||
from langgraph.config import get_config
|
from langgraph.config import get_config
|
||||||
from langgraph.runtime import Runtime
|
from langgraph.runtime import Runtime
|
||||||
|
|
||||||
from ..utils.github import (
|
from ..utils.git_utils import (
|
||||||
create_github_pr,
|
|
||||||
get_github_default_branch,
|
|
||||||
git_add_all,
|
git_add_all,
|
||||||
git_checkout_branch,
|
git_checkout_branch,
|
||||||
git_commit,
|
git_commit,
|
||||||
@ -29,7 +27,6 @@ from ..utils.github import (
|
|||||||
git_has_unpushed_commits,
|
git_has_unpushed_commits,
|
||||||
git_push,
|
git_push,
|
||||||
)
|
)
|
||||||
from ..utils.github_token import get_github_token
|
|
||||||
from ..utils.sandbox_paths import aresolve_repo_dir
|
from ..utils.sandbox_paths import aresolve_repo_dir
|
||||||
from ..utils.sandbox_state import get_sandbox_backend
|
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
|
# Tool already handled commit/push/PR creation
|
||||||
return None
|
return None
|
||||||
|
|
||||||
pr_title = pr_payload.get("title", "feat: Open SWE PR")
|
pr_title = pr_payload.get("title", "feat: galaxis-agent PR")
|
||||||
pr_body = pr_payload.get("body", "Automated PR created by Open SWE agent.")
|
pr_body = pr_payload.get("body", "Automated PR created by galaxis-agent.")
|
||||||
commit_message = pr_payload.get("commit_message", pr_title)
|
commit_message = pr_payload.get("commit_message", pr_title)
|
||||||
|
|
||||||
if not thread_id:
|
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)
|
logger.info("Changes detected, preparing PR for thread %s", thread_id)
|
||||||
|
|
||||||
current_branch = await asyncio.to_thread(git_current_branch, sandbox_backend, repo_dir)
|
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:
|
if current_branch != target_branch:
|
||||||
await asyncio.to_thread(git_checkout_branch, sandbox_backend, repo_dir, 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,
|
git_config_user,
|
||||||
sandbox_backend,
|
sandbox_backend,
|
||||||
repo_dir,
|
repo_dir,
|
||||||
"open-swe[bot]",
|
"galaxis-agent[bot]",
|
||||||
"open-swe@users.noreply.github.com",
|
"galaxis-agent@users.noreply.gitea.local",
|
||||||
)
|
)
|
||||||
await asyncio.to_thread(git_add_all, sandbox_backend, repo_dir)
|
await asyncio.to_thread(git_add_all, sandbox_backend, repo_dir)
|
||||||
await asyncio.to_thread(git_commit, sandbox_backend, repo_dir, commit_message)
|
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(
|
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)
|
# TODO: Phase 2 - use GiteaClient to create PR via Gitea API
|
||||||
logger.info("Using base branch: %s", base_branch)
|
logger.info("Pushed to branch %s, PR creation pending Gitea integration", target_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,
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info("After-agent middleware completed successfully")
|
logger.info("After-agent middleware completed successfully")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user