feat(repair-agent): auto-merge fix branch to main after repair
All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 9m30s
All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 9m30s
After pushing the fix branch, automatically merge it back to main and push, so that CI/CD is triggered with the fix. Also cleans up the remote fix branch after merge. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
50301dfb8c
commit
9a347d7929
@ -204,13 +204,18 @@ class RepairEngine:
|
|||||||
modified_files=modified_files, diff=diff,
|
modified_files=modified_files, diff=diff,
|
||||||
))
|
))
|
||||||
|
|
||||||
# 自动提交并推送(仅在 Git 启用时)
|
# 自动提交、合并到 main 并推送(仅在 Git 启用时)
|
||||||
if git_enabled and auto_commit and modified_files and git_manager:
|
if git_enabled and auto_commit and modified_files and git_manager:
|
||||||
bug_ids = ", ".join([f"#{b.id}" for b in bugs])
|
bug_ids = ", ".join([f"#{b.id}" for b in bugs])
|
||||||
git_manager.commit(f"fix: auto repair bugs {bug_ids}")
|
git_manager.commit(f"fix: auto repair bugs {bug_ids}")
|
||||||
logger.info("代码已提交")
|
logger.info("代码已提交")
|
||||||
git_manager.push()
|
git_manager.push()
|
||||||
logger.info("代码已推送到远程")
|
logger.info("fix 分支已推送")
|
||||||
|
# 合并 fix 分支到 main 并推送,触发 CI/CD
|
||||||
|
if git_manager.merge_to_main_and_push():
|
||||||
|
logger.info("已合并到 main 并推送")
|
||||||
|
else:
|
||||||
|
logger.warning("合并到 main 失败,请手动合并")
|
||||||
elif not git_enabled and auto_commit:
|
elif not git_enabled and auto_commit:
|
||||||
logger.info("未配置 GitHub 仓库,跳过自动提交")
|
logger.info("未配置 GitHub 仓库,跳过自动提交")
|
||||||
|
|
||||||
|
|||||||
@ -172,6 +172,40 @@ class GitManager:
|
|||||||
logger.error(f"推送失败: {e}")
|
logger.error(f"推送失败: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def merge_to_main_and_push(self) -> bool:
|
||||||
|
"""将当前 fix 分支合并到 main 并推送,然后删除 fix 分支"""
|
||||||
|
if not self.repo:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
fix_branch = self.repo.active_branch.name
|
||||||
|
|
||||||
|
# 切换到 main(或 master)
|
||||||
|
main_name = "main" if "main" in self.repo.heads else "master"
|
||||||
|
self.repo.heads[main_name].checkout()
|
||||||
|
|
||||||
|
# 合并 fix 分支
|
||||||
|
self.repo.git.merge(fix_branch)
|
||||||
|
logger.info(f"合并 {fix_branch} → {main_name}")
|
||||||
|
|
||||||
|
# 推送 main
|
||||||
|
origin = self.repo.remotes.origin
|
||||||
|
origin.push(refspec=f"{main_name}:{main_name}")
|
||||||
|
logger.info(f"推送 {main_name} 成功")
|
||||||
|
|
||||||
|
# 删除本地和远程 fix 分支
|
||||||
|
self.repo.git.branch("-d", fix_branch)
|
||||||
|
try:
|
||||||
|
origin.push(refspec=f":{fix_branch}")
|
||||||
|
logger.info(f"删除远程分支 {fix_branch}")
|
||||||
|
except Exception:
|
||||||
|
pass # 远程分支可能不存在
|
||||||
|
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"合并到 main 失败: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
def reset_hard(self) -> bool:
|
def reset_hard(self) -> bool:
|
||||||
"""重置所有更改"""
|
"""重置所有更改"""
|
||||||
if not self.repo:
|
if not self.repo:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user