Compare commits
1 Commits
d93074f184
...
79672c34dd
Author | SHA1 | Date | |
---|---|---|---|
79672c34dd |
|
@ -155,16 +155,15 @@ def create_aider_command(issue: str) -> list[str]:
|
||||||
AIDER_LINT,
|
AIDER_LINT,
|
||||||
'--auto-test',
|
'--auto-test',
|
||||||
'--no-auto-lint',
|
'--no-auto-lint',
|
||||||
|
'--api-key',
|
||||||
|
secrets.llm_api_key(),
|
||||||
'--read',
|
'--read',
|
||||||
'CONVENTIONS.md',
|
'CONVENTIONS.md',
|
||||||
'--message',
|
'--message',
|
||||||
LLM_MESSAGE_FORMAT.format(issue=issue),
|
LLM_MESSAGE_FORMAT.format(issue=issue),
|
||||||
'--yes',
|
'--yes-always',
|
||||||
]
|
]
|
||||||
|
|
||||||
for key in secrets.llm_api_keys():
|
|
||||||
l += ['--api-key', key]
|
|
||||||
|
|
||||||
if True:
|
if True:
|
||||||
l.append('--cache-prompts')
|
l.append('--cache-prompts')
|
||||||
|
|
||||||
|
@ -256,9 +255,15 @@ def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> b
|
||||||
True if there are commits on the current branch not in the base branch, False otherwise.
|
True if there are commits on the current branch not in the base branch, False otherwise.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
commit_messages = get_commit_messages(cwd, base_branch, current_branch)
|
result = subprocess.run(
|
||||||
return bool(list(commit_messages))
|
['git', 'log', f'{base_branch}..{current_branch}', '--oneline'],
|
||||||
except Exception:
|
check=True,
|
||||||
|
cwd=cwd,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
return bool(result.stdout.strip())
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
logger.exception('Failed to check commits on branch %s', current_branch)
|
logger.exception('Failed to check commits on branch %s', current_branch)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -278,9 +283,6 @@ def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool:
|
||||||
return result.returncode == 0
|
return result.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
SKIP_AIDER = False
|
|
||||||
|
|
||||||
|
|
||||||
def solve_issue_in_repository(
|
def solve_issue_in_repository(
|
||||||
args,
|
args,
|
||||||
tmpdirname: Path,
|
tmpdirname: Path,
|
||||||
|
@ -290,8 +292,6 @@ def solve_issue_in_repository(
|
||||||
issue_number: str,
|
issue_number: str,
|
||||||
gitea_client=None,
|
gitea_client=None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
logger.info('### %s #####', issue_title)
|
|
||||||
|
|
||||||
repo_url = f'{args.gitea_url}:{args.owner}/{args.repo}.git'.replace(
|
repo_url = f'{args.gitea_url}:{args.owner}/{args.repo}.git'.replace(
|
||||||
'https://',
|
'https://',
|
||||||
'git@',
|
'git@',
|
||||||
|
@ -320,15 +320,11 @@ def solve_issue_in_repository(
|
||||||
|
|
||||||
# Run aider
|
# Run aider
|
||||||
issue_content = f'# {issue_title}\n{issue_description}'
|
issue_content = f'# {issue_title}\n{issue_description}'
|
||||||
if not SKIP_AIDER:
|
succeeded = run_cmd(
|
||||||
succeeded = run_cmd(
|
create_aider_command(issue_content),
|
||||||
create_aider_command(issue_content),
|
tmpdirname,
|
||||||
tmpdirname,
|
check=False,
|
||||||
check=False,
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
logger.warning('Skipping aider command (for testing)')
|
|
||||||
succeeded = True
|
|
||||||
if not succeeded:
|
if not succeeded:
|
||||||
logger.error('Aider invocation failed for issue #%s', issue_number)
|
logger.error('Aider invocation failed for issue #%s', issue_number)
|
||||||
return False
|
return False
|
||||||
|
@ -348,7 +344,7 @@ def solve_issue_in_repository(
|
||||||
)
|
)
|
||||||
files_changed = result.stdout.strip()
|
files_changed = result.stdout.strip()
|
||||||
|
|
||||||
if not files_changed and not SKIP_AIDER:
|
if not files_changed:
|
||||||
logger.info(
|
logger.info(
|
||||||
'Aider did not make any changes beyond the initial ruff pass for issue #%s',
|
'Aider did not make any changes beyond the initial ruff pass for issue #%s',
|
||||||
issue_number,
|
issue_number,
|
||||||
|
|
|
@ -163,6 +163,7 @@ class GiteaClient:
|
||||||
'body': body,
|
'body': body,
|
||||||
'head': head,
|
'head': head,
|
||||||
'base': base,
|
'base': base,
|
||||||
|
'labels': labels,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.session.post(url, json=json_data)
|
response = self.session.post(url, json=json_data)
|
||||||
|
|
|
@ -3,9 +3,9 @@ import secret_loader
|
||||||
SECRETS = secret_loader.SecretLoader()
|
SECRETS = secret_loader.SecretLoader()
|
||||||
|
|
||||||
|
|
||||||
def llm_api_keys() -> list[str]:
|
def llm_api_key():
|
||||||
return SECRETS.load_or_fail('LLM_API_KEY').strip().split('\n')
|
return SECRETS.load_or_fail('LLM_API_KEY')
|
||||||
|
|
||||||
|
|
||||||
def gitea_token() -> str:
|
def gitea_token():
|
||||||
return SECRETS.load_or_fail('GITEA_TOKEN')
|
return SECRETS.load_or_fail('GITEA_TOKEN')
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
from pathlib import Path
|
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from aider_gitea import has_commits_on_branch
|
|
||||||
|
|
||||||
|
|
||||||
class TestHasCommitsOnBranch:
|
|
||||||
def setup_method(self):
|
|
||||||
self.cwd = Path('/tmp/test-repo')
|
|
||||||
self.base_branch = 'main'
|
|
||||||
self.current_branch = 'feature-branch'
|
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
|
||||||
def test_has_commits_true(self, mock_get_commit_messages):
|
|
||||||
# Setup mock to return some commit messages
|
|
||||||
mock_get_commit_messages.return_value = ['Commit 1', 'Commit 2']
|
|
||||||
|
|
||||||
# Test function returns True when there are commits
|
|
||||||
assert (
|
|
||||||
has_commits_on_branch(self.cwd, self.base_branch, self.current_branch)
|
|
||||||
is True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Verify get_commit_messages was called with correct arguments
|
|
||||||
mock_get_commit_messages.assert_called_once_with(
|
|
||||||
self.cwd, self.base_branch, self.current_branch,
|
|
||||||
)
|
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
|
||||||
def test_has_commits_false(self, mock_get_commit_messages):
|
|
||||||
# Setup mock to return empty list
|
|
||||||
mock_get_commit_messages.return_value = []
|
|
||||||
|
|
||||||
# Test function returns False when there are no commits
|
|
||||||
assert (
|
|
||||||
has_commits_on_branch(self.cwd, self.base_branch, self.current_branch)
|
|
||||||
is False
|
|
||||||
)
|
|
||||||
|
|
||||||
# Verify get_commit_messages was called with correct arguments
|
|
||||||
mock_get_commit_messages.assert_called_once_with(
|
|
||||||
self.cwd, self.base_branch, self.current_branch,
|
|
||||||
)
|
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
|
||||||
def test_has_commits_exception(self, mock_get_commit_messages):
|
|
||||||
# Setup mock to raise an exception
|
|
||||||
mock_get_commit_messages.side_effect = Exception('Git command failed')
|
|
||||||
|
|
||||||
# Test function returns False when an exception occurs
|
|
||||||
assert (
|
|
||||||
has_commits_on_branch(self.cwd, self.base_branch, self.current_branch)
|
|
||||||
is False
|
|
||||||
)
|
|
|
@ -19,7 +19,7 @@ class TestSolveIssueInRepository:
|
||||||
self.issue_description = 'This is a test issue'
|
self.issue_description = 'This is a test issue'
|
||||||
self.issue_number = '123'
|
self.issue_number = '123'
|
||||||
|
|
||||||
@patch('aider_gitea.secrets.llm_api_keys', return_value='fake-api-key')
|
@patch('aider_gitea.secrets.llm_api_key', return_value='fake-api-key')
|
||||||
@patch('aider_gitea.run_cmd')
|
@patch('aider_gitea.run_cmd')
|
||||||
@patch('aider_gitea.push_changes')
|
@patch('aider_gitea.push_changes')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
|
@ -59,7 +59,7 @@ class TestSolveIssueInRepository:
|
||||||
assert mock_run_cmd.call_count >= 8 # Verify all expected commands were run
|
assert mock_run_cmd.call_count >= 8 # Verify all expected commands were run
|
||||||
mock_push_changes.assert_called_once()
|
mock_push_changes.assert_called_once()
|
||||||
|
|
||||||
@patch('aider_gitea.secrets.llm_api_keys', return_value='fake-api-key')
|
@patch('aider_gitea.secrets.llm_api_key', return_value='fake-api-key')
|
||||||
@patch('aider_gitea.run_cmd')
|
@patch('aider_gitea.run_cmd')
|
||||||
@patch('aider_gitea.push_changes')
|
@patch('aider_gitea.push_changes')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user