Compare commits
4 Commits
c4083db17e
...
5a899c05fb
Author | SHA1 | Date | |
---|---|---|---|
5a899c05fb | |||
d3d9a1b3fe | |||
d0a0bf0db3 | |||
fca65f73c5 |
|
@ -14,9 +14,10 @@ import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import secret_loader
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from . import secrets
|
||||||
|
|
||||||
def generate_branch_name(issue_title: str) -> str:
|
def generate_branch_name(issue_title: str) -> str:
|
||||||
"""
|
"""
|
||||||
Create a branch name by sanitizing the issue title.
|
Create a branch name by sanitizing the issue title.
|
||||||
|
@ -33,11 +34,6 @@ AIDER_LINT="ruff format; ruff check --fix --ignore RUF022 --ignore PGH004; ruff
|
||||||
|
|
||||||
MODEL = 'o3-mini'
|
MODEL = 'o3-mini'
|
||||||
|
|
||||||
SECRETS = secret_loader.SecretLoader()
|
|
||||||
LLM_API_KEY = SECRETS.load_or_fail('LLM_API_KEY')
|
|
||||||
GITEA_TOKEN = SECRETS.load_or_fail('GITEA_TOKEN')
|
|
||||||
|
|
||||||
|
|
||||||
def create_aider_command(issue: str) -> list[str]:
|
def create_aider_command(issue: str) -> list[str]:
|
||||||
return [
|
return [
|
||||||
'aider',
|
'aider',
|
||||||
|
@ -47,7 +43,7 @@ def create_aider_command(issue: str) -> list[str]:
|
||||||
'--lint-cmd', AIDER_LINT,
|
'--lint-cmd', AIDER_LINT,
|
||||||
'--auto-test',
|
'--auto-test',
|
||||||
'--no-auto-lint',
|
'--no-auto-lint',
|
||||||
'--api-key', LLM_API_KEY,
|
'--api-key', secrets.llm_api_key(),
|
||||||
'--read', 'CONVENTIONS.md',
|
'--read', 'CONVENTIONS.md',
|
||||||
'--message', "First, write unit tests that validate your changes. Then, solve the issue. Issue details:\n" + issue,
|
'--message', "First, write unit tests that validate your changes. Then, solve the issue. Issue details:\n" + issue,
|
||||||
'--yes-always',
|
'--yes-always',
|
||||||
|
@ -112,6 +108,21 @@ def parse_args():
|
||||||
parser.add_argument("--base-branch", default="main", help="Base branch to use for new branches (default: main)")
|
parser.add_argument("--base-branch", default="main", help="Base branch to use for new branches (default: main)")
|
||||||
return parser.parse_args()
|
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:
|
def run_cmd(cmd: list[str], cwd:Path|None=None) -> None:
|
||||||
print(cmd)
|
print(cmd)
|
||||||
subprocess.run(cmd, check=True, cwd=cwd)
|
subprocess.run(cmd, check=True, cwd=cwd)
|
||||||
|
@ -124,13 +135,13 @@ def process_issue(args, tmpdirname: Path, branch_name: str, issue_title: str, is
|
||||||
run_cmd(["git", "checkout", "-b", branch_name], tmpdirname)
|
run_cmd(["git", "checkout", "-b", branch_name], tmpdirname)
|
||||||
run_cmd(create_aider_command(f'# {issue_title}\n{issue_description}'), tmpdirname)
|
run_cmd(create_aider_command(f'# {issue_title}\n{issue_description}'), tmpdirname)
|
||||||
run_cmd(["git", "add", "."], 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():
|
def main():
|
||||||
logging.basicConfig(level='INFO')
|
logging.basicConfig(level='INFO')
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
client = GiteaClient(args.gitea_url, GITEA_TOKEN )
|
client = GiteaClient(args.gitea_url, secrets.gitea_token())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
issues = client.get_issues(args.owner, args.repo)
|
issues = client.get_issues(args.owner, args.repo)
|
||||||
|
|
9
aider_gitea/secrets.py
Normal file
9
aider_gitea/secrets.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
SECRETS = secret_loader.SecretLoader()
|
||||||
|
|
||||||
|
import secret_loader
|
||||||
|
|
||||||
|
def llm_api_key():
|
||||||
|
return SECRETS.load_or_fail('LLM_API_KEY')
|
||||||
|
|
||||||
|
def gitea_token():
|
||||||
|
return SECRETS.load_or_fail('GITEA_TOKEN')
|
31
test/test_agit.py
Normal file
31
test/test_agit.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
def test_push_changes(monkeypatch):
|
||||||
|
captured = {}
|
||||||
|
|
||||||
|
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")
|
||||||
|
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
|
Loading…
Reference in New Issue
Block a user