From d0a0bf0db36d266d1b4e067b99e0deb45d757379 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sun, 13 Apr 2025 16:10:05 +0200 Subject: [PATCH 1/3] feat: add push_changes helper function and update process_issue logic --- aider_gitea/__main__.py | 17 ++++++++++++++++- test/test_agit.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/test_agit.py diff --git a/aider_gitea/__main__.py b/aider_gitea/__main__.py index ac7ab0a..0bb6900 100644 --- a/aider_gitea/__main__.py +++ b/aider_gitea/__main__.py @@ -108,6 +108,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) @@ -120,7 +135,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') diff --git a/test/test_agit.py b/test/test_agit.py new file mode 100644 index 0000000..6b15c31 --- /dev/null +++ b/test/test_agit.py @@ -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 -- 2.45.1 From d3d9a1b3fe6fcf4c560b99eab1ba01cfbbb76e0e Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sun, 13 Apr 2025 16:10:09 +0200 Subject: [PATCH 2/3] test: mock secret loading in test_push_changes to avoid failures --- test/test_agit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_agit.py b/test/test_agit.py index 6b15c31..f3291a5 100644 --- a/test/test_agit.py +++ b/test/test_agit.py @@ -6,7 +6,7 @@ def test_push_changes(monkeypatch): monkeypatch.setattr("aider_gitea.__main__.run_cmd", fake_run_cmd) - # Test parameters + monkeypatch.setattr("aider_gitea.__main__.SECRETS.load_or_fail", lambda x: "mocked_secret") branch = "feature/test-issue" title = "Test Issue Title" description = "Test Issue Description" -- 2.45.1 From 5a899c05fb57961253d67c69f7832dd443ccf3d0 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Sun, 13 Apr 2025 16:10:13 +0200 Subject: [PATCH 3/3] test: Mock secret loading in test_push_changes to avoid failures --- test/test_agit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_agit.py b/test/test_agit.py index f3291a5..40b3fa0 100644 --- a/test/test_agit.py +++ b/test/test_agit.py @@ -4,6 +4,7 @@ def test_push_changes(monkeypatch): def fake_run_cmd(cmd, cwd=None): captured["cmd"] = cmd + monkeypatch.setattr("aider_gitea.__main__.SECRETS.load_or_fail", lambda x: "mocked_secret") monkeypatch.setattr("aider_gitea.__main__.run_cmd", fake_run_cmd) monkeypatch.setattr("aider_gitea.__main__.SECRETS.load_or_fail", lambda x: "mocked_secret") -- 2.45.1