feat: add push_changes helper function and update process_issue logic

This commit is contained in:
Jon Michael Aanes (aider) 2025-04-13 16:10:05 +02:00
parent 8850ce06cb
commit fea7eab276
2 changed files with 46 additions and 1 deletions

View File

@ -112,6 +112,21 @@ def parse_args():
parser.add_argument("--base-branch", default="main", help="Base branch to use for new branches (default: main)")
return parser.parse_args()
def push_changes(branch_name: str, issue_title: str, issue_description: str, base_branch: str) -> None:
cmd = [
"git",
"push",
"origin",
f"HEAD:refs/for/{base_branch}",
"-o",
f"topic={branch_name}",
"-o",
f"title={issue_title}",
"-o",
f"description={issue_description}"
]
run_cmd(cmd)
def run_cmd(cmd: list[str], cwd:Path|None=None) -> None:
print(cmd)
subprocess.run(cmd, check=True, cwd=cwd)
@ -124,7 +139,7 @@ def process_issue(args, tmpdirname: Path, branch_name: str, issue_title: str, is
run_cmd(["git", "checkout", "-b", branch_name], tmpdirname)
run_cmd(create_aider_command(f'# {issue_title}\n{issue_description}'), tmpdirname)
run_cmd(["git", "add", "."], tmpdirname)
run_cmd(["git", "push", "origin", branch_name], tmpdirname)
push_changes(branch_name, issue_title, issue_description, args.base_branch)
def main():
logging.basicConfig(level='INFO')

30
test/test_agit.py Normal file
View File

@ -0,0 +1,30 @@
def test_push_changes(monkeypatch):
captured = {}
def fake_run_cmd(cmd, cwd=None):
captured["cmd"] = cmd
monkeypatch.setattr("aider_gitea.__main__.run_cmd", fake_run_cmd)
# Test parameters
branch = "feature/test-issue"
title = "Test Issue Title"
description = "Test Issue Description"
base_branch = "main"
from aider_gitea.__main__ import push_changes
push_changes(branch, title, description, base_branch)
expected_cmd = [
"git",
"push",
"origin",
f"HEAD:refs/for/{base_branch}",
"-o",
f"topic={branch}",
"-o",
f"title={title}",
"-o",
f"description={description}"
]
assert captured["cmd"] == expected_cmd