This commit is contained in:
Jon Michael Aanes 2025-04-21 10:21:24 +02:00
parent d196155bf7
commit 727b788d01

View File

@ -149,20 +149,9 @@ AIDER_LINT = bash_cmd(
)
LLM_MESSAGE_FORMAT = """
{issue}
# Solution Details
For code tasks:
1. Create a plan for how to solve the issue.
2. Write unit tests that proves that your solution works.
3. Then, solve the issue by writing the required code.
"""
MODEL = None
LLM_MESSAGE_FORMAT = """/code {issue}"""
MODEL = 'ollama/gemma3:27b'
def create_aider_command(issue: str) -> list[str]:
l = [
@ -171,6 +160,7 @@ def create_aider_command(issue: str) -> list[str]:
'english',
'--no-stream',
'--no-analytics',
'--no-check-update',
'--test-cmd',
AIDER_TEST,
'--lint-cmd',
@ -309,7 +299,7 @@ SKIP_AIDER = False
def solve_issue_in_repository(
repository_config: RepositoryConfig,
tmpdirname: Path,
repository_path: Path,
branch_name: str,
issue_title: str,
issue_description: str,
@ -319,32 +309,31 @@ def solve_issue_in_repository(
logger.info('### %s #####', issue_title)
# Setup repository
run_cmd(['git', 'clone', repository_config.repo_url(), tmpdirname])
run_cmd(['bash', '-c', AIDER_TEST], tmpdirname)
run_cmd(['git', 'checkout', repository_config.base_branch], tmpdirname)
run_cmd(['git', 'checkout', '-b', branch_name], tmpdirname)
run_cmd(['git', 'clone', repository_config.repo_url(), repository_path])
run_cmd(['bash', '-c', AIDER_TEST], repository_path)
run_cmd(['git', 'checkout', repository_config.base_branch], repository_path)
run_cmd(['git', 'checkout', branch_name], repository_path)
# Run initial ruff pass before aider
run_cmd(['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX], tmpdirname, check=False)
run_cmd(['git', 'add', '.'], tmpdirname)
run_cmd(['git', 'commit', '-m', 'Initial ruff pass'], tmpdirname, check=False)
run_cmd(['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX], repository_path, check=False)
run_cmd(['git', 'add', '.'], repository_path)
run_cmd(['git', 'commit', '-m', 'Initial ruff pass'], repository_path, check=False)
# Save the commit hash after ruff but before aider
result = subprocess.run(
pre_aider_commit = subprocess.run(
['git', 'rev-parse', 'HEAD'],
check=True,
cwd=tmpdirname,
cwd=repository_path,
capture_output=True,
text=True,
)
pre_aider_commit = result.stdout.strip()
).stdout.strip()
# Run aider
issue_content = f'# {issue_title}\n{issue_description}'
if not SKIP_AIDER:
succeeded = run_cmd(
create_aider_command(issue_content),
tmpdirname,
repository_path,
check=False,
)
else:
@ -355,21 +344,12 @@ def solve_issue_in_repository(
return IssueResolution(False)
# Auto-fix standard code quality stuff after aider
run_cmd(['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX], tmpdirname, check=False)
run_cmd(['git', 'add', '.'], tmpdirname)
run_cmd(['git', 'commit', '-m', 'Ruff after aider'], tmpdirname, check=False)
run_cmd(['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX], repository_path, check=False)
run_cmd(['git', 'add', '.'], repository_path)
run_cmd(['git', 'commit', '-m', 'Ruff after aider'], repository_path, check=False)
# Check if aider made any changes beyond the initial ruff pass
result = subprocess.run(
['git', 'diff', pre_aider_commit, 'HEAD', '--name-only'],
check=True,
cwd=tmpdirname,
capture_output=True,
text=True,
)
files_changed = result.stdout.strip()
if not files_changed and not SKIP_AIDER:
if not has_commits_on_branch(repository_path, repository_config.base_branch, branch_name) and not SKIP_AIDER:
logger.info(
'Aider did not make any changes beyond the initial ruff pass for issue #%s',
issue_number,
@ -379,7 +359,7 @@ def solve_issue_in_repository(
# Push changes
return push_changes(
repository_config,
tmpdirname,
repository_path,
branch_name,
issue_number,
issue_title,
@ -417,10 +397,10 @@ def solve_issues_in_repository(
continue
branch_name = generate_branch_name(issue_number, title)
with tempfile.TemporaryDirectory() as tmpdirname:
with tempfile.TemporaryDirectory() as repository_path:
issue_resolution = solve_issue_in_repository(
repository_config,
Path(tmpdirname),
Path(repository_path),
branch_name,
title,
issue_description,