Create pull request and push after every iteration #88
|
@ -149,12 +149,15 @@ AIDER_LINT = bash_cmd(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
LLM_MESSAGE_FORMAT = """{issue}\nDo not wait for explicit approval before working on code changes."""
|
LLM_MESSAGE_FORMAT = (
|
||||||
|
"""{issue}\nDo not wait for explicit approval before working on code changes."""
|
||||||
|
)
|
||||||
|
|
||||||
#CODE_MODEL = 'ollama/gemma3:4b'
|
# CODE_MODEL = 'ollama/gemma3:4b'
|
||||||
CODE_MODEL = 'o3'
|
CODE_MODEL = 'o3'
|
||||||
EVALUATOR_MODEL = 'ollama/gemma3:27b'
|
EVALUATOR_MODEL = 'ollama/gemma3:27b'
|
||||||
|
|
||||||
|
|
||||||
def create_aider_command(issue: str) -> list[str]:
|
def create_aider_command(issue: str) -> list[str]:
|
||||||
l = [
|
l = [
|
||||||
'aider',
|
'aider',
|
||||||
|
@ -235,7 +238,6 @@ def get_diff(cwd: Path, base_branch: str, current_branch: str) -> str:
|
||||||
return result.stdout.strip()
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def push_changes(
|
def push_changes(
|
||||||
repository_config: RepositoryConfig,
|
repository_config: RepositoryConfig,
|
||||||
cwd: Path,
|
cwd: Path,
|
||||||
|
@ -251,7 +253,9 @@ def push_changes(
|
||||||
|
|
||||||
# Get commit messages for PR description
|
# Get commit messages for PR description
|
||||||
commit_messages = get_commit_messages(
|
commit_messages = get_commit_messages(
|
||||||
cwd, repository_config.base_branch, branch_name,
|
cwd,
|
||||||
|
repository_config.base_branch,
|
||||||
|
branch_name,
|
||||||
)
|
)
|
||||||
description = f'This pull request resolves #{issue_number}\n\n'
|
description = f'This pull request resolves #{issue_number}\n\n'
|
||||||
|
|
||||||
|
@ -277,7 +281,9 @@ def push_changes(
|
||||||
|
|
||||||
# Extract PR number and URL if available
|
# Extract PR number and URL if available
|
||||||
return IssueResolution(
|
return IssueResolution(
|
||||||
True, str(pr_response.get('number')), pr_response.get('html_url'),
|
True,
|
||||||
|
str(pr_response.get('number')),
|
||||||
|
pr_response.get('html_url'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -314,6 +320,7 @@ def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool:
|
||||||
result = subprocess.run(cmd, check=check, cwd=cwd)
|
result = subprocess.run(cmd, check=check, cwd=cwd)
|
||||||
return result.returncode == 0
|
return result.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
def issue_solution_round(repository_path, issue_content):
|
def issue_solution_round(repository_path, issue_content):
|
||||||
# Primary Aider command
|
# Primary Aider command
|
||||||
aider_command = create_aider_command(issue_content)
|
aider_command = create_aider_command(issue_content)
|
||||||
|
@ -333,6 +340,7 @@ def issue_solution_round(repository_path, issue_content):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def run_ollama(cwd: Path, texts: list[str]) -> str:
|
def run_ollama(cwd: Path, texts: list[str]) -> str:
|
||||||
cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')]
|
cmd = ['ollama', 'run', EVALUATOR_MODEL.removeprefix('ollama/')]
|
||||||
print(cmd)
|
print(cmd)
|
||||||
|
@ -348,6 +356,7 @@ def run_ollama(cwd: Path, texts: list[str]) -> str:
|
||||||
print(stdout)
|
print(stdout)
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
|
|
||||||
def parse_yes_no_answer(text: str) -> bool | None:
|
def parse_yes_no_answer(text: str) -> bool | None:
|
||||||
text = text.lower().strip()
|
text = text.lower().strip()
|
||||||
words = text.split('\n \t.,?-')
|
words = text.split('\n \t.,?-')
|
||||||
|
@ -358,6 +367,7 @@ def parse_yes_no_answer(text: str) -> bool | None:
|
||||||
return False
|
return False
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
|
def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
|
||||||
texts = list(initial_texts)
|
texts = list(initial_texts)
|
||||||
texts.append('Think through your answer.')
|
texts.append('Think through your answer.')
|
||||||
|
@ -370,21 +380,27 @@ def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
|
||||||
texts.append(response)
|
texts.append(response)
|
||||||
texts.append('Please answer either "yes" or "no".')
|
texts.append('Please answer either "yes" or "no".')
|
||||||
|
|
||||||
|
|
||||||
def verify_solution(repository_path: Path, issue_content: str) -> bool:
|
def verify_solution(repository_path: Path, issue_content: str) -> bool:
|
||||||
summary = run_ollama(
|
summary = run_ollama(
|
||||||
repository_path,
|
repository_path,
|
||||||
['Concisely summarize following changeset',
|
[
|
||||||
get_diff(repository_path, 'HEAD', 'main')
|
'Concisely summarize following changeset',
|
||||||
])
|
get_diff(repository_path, 'HEAD', 'main'),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
return run_ollama_and_get_yes_or_no(
|
return run_ollama_and_get_yes_or_no(
|
||||||
repository_path,
|
repository_path,
|
||||||
['Does this changeset accomplish the entire task?',
|
[
|
||||||
|
'Does this changeset accomplish the entire task?',
|
||||||
'# Change set',
|
'# Change set',
|
||||||
summary,
|
summary,
|
||||||
'# Issue',
|
'# Issue',
|
||||||
issue_content,
|
issue_content,
|
||||||
])
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_head_commit_hash(repository_path: Path) -> str:
|
def get_head_commit_hash(repository_path: Path) -> str:
|
||||||
return subprocess.run(
|
return subprocess.run(
|
||||||
|
@ -439,12 +455,8 @@ def solve_issue_in_repository(
|
||||||
)
|
)
|
||||||
return IssueResolution(False)
|
return IssueResolution(False)
|
||||||
|
|
||||||
# Verify whether this is a satisfactory solution
|
# Push changes and create/update the pull request on every iteration
|
||||||
if verify_solution(repository_path, issue_content):
|
resolution = push_changes(
|
||||||
break
|
|
||||||
|
|
||||||
# Push changes
|
|
||||||
return push_changes(
|
|
||||||
repository_config,
|
repository_config,
|
||||||
repository_path,
|
repository_path,
|
||||||
branch_name,
|
branch_name,
|
||||||
|
@ -452,10 +464,18 @@ def solve_issue_in_repository(
|
||||||
issue_title,
|
issue_title,
|
||||||
gitea_client,
|
gitea_client,
|
||||||
)
|
)
|
||||||
|
if not resolution.success:
|
||||||
|
return resolution
|
||||||
|
|
||||||
|
# Verify whether this is a satisfactory solution
|
||||||
|
if verify_solution(repository_path, issue_content):
|
||||||
|
return resolution
|
||||||
|
|
||||||
|
|
||||||
def solve_issues_in_repository(
|
def solve_issues_in_repository(
|
||||||
repository_config: RepositoryConfig, client, seen_issues_db,
|
repository_config: RepositoryConfig,
|
||||||
|
client,
|
||||||
|
seen_issues_db,
|
||||||
):
|
):
|
||||||
"""Process all open issues with the 'aider' label.
|
"""Process all open issues with the 'aider' label.
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,9 @@ class TestHasCommitsOnBranch:
|
||||||
|
|
||||||
# Verify get_commit_messages was called with correct arguments
|
# Verify get_commit_messages was called with correct arguments
|
||||||
mock_get_commit_messages.assert_called_once_with(
|
mock_get_commit_messages.assert_called_once_with(
|
||||||
self.cwd, self.base_branch, self.current_branch,
|
self.cwd,
|
||||||
|
self.base_branch,
|
||||||
|
self.current_branch,
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
@patch('aider_gitea.get_commit_messages')
|
||||||
|
@ -39,7 +41,9 @@ class TestHasCommitsOnBranch:
|
||||||
|
|
||||||
# Verify get_commit_messages was called with correct arguments
|
# Verify get_commit_messages was called with correct arguments
|
||||||
mock_get_commit_messages.assert_called_once_with(
|
mock_get_commit_messages.assert_called_once_with(
|
||||||
self.cwd, self.base_branch, self.current_branch,
|
self.cwd,
|
||||||
|
self.base_branch,
|
||||||
|
self.current_branch,
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
@patch('aider_gitea.get_commit_messages')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user