Compare commits
1 Commits
3fa44e08d8
...
1a260b3848
Author | SHA1 | Date | |
---|---|---|---|
1a260b3848 |
|
@ -155,16 +155,15 @@ def create_aider_command(issue: str) -> list[str]:
|
|||
AIDER_LINT,
|
||||
'--auto-test',
|
||||
'--no-auto-lint',
|
||||
'--api-key',
|
||||
secrets.llm_api_key(),
|
||||
'--read',
|
||||
'CONVENTIONS.md',
|
||||
'--message',
|
||||
LLM_MESSAGE_FORMAT.format(issue=issue),
|
||||
'--yes',
|
||||
'--yes-always',
|
||||
]
|
||||
|
||||
for key in secrets.llm_api_keys():
|
||||
l += ['--api-key', key]
|
||||
|
||||
if True:
|
||||
l.append('--cache-prompts')
|
||||
|
||||
|
@ -212,13 +211,11 @@ def push_changes(
|
|||
gitea_client,
|
||||
owner: str,
|
||||
repo: str,
|
||||
seen_issues_db=None,
|
||||
issue_text: str = None,
|
||||
) -> tuple[bool, str, str]:
|
||||
) -> bool:
|
||||
# Check if there are any commits on the branch before pushing
|
||||
if not has_commits_on_branch(cwd, base_branch, branch_name):
|
||||
logger.info('No commits made on branch %s, skipping push', branch_name)
|
||||
return False, None, None
|
||||
return False
|
||||
|
||||
# Get commit messages for PR description
|
||||
commit_messages = get_commit_messages(cwd, base_branch, branch_name)
|
||||
|
@ -234,7 +231,7 @@ def push_changes(
|
|||
run_cmd(cmd, cwd)
|
||||
|
||||
# Then create the PR with the aider label
|
||||
pr_response = gitea_client.create_pull_request(
|
||||
gitea_client.create_pull_request(
|
||||
owner=owner,
|
||||
repo=repo,
|
||||
title=issue_title,
|
||||
|
@ -243,22 +240,7 @@ def push_changes(
|
|||
base=base_branch,
|
||||
labels=['aider'],
|
||||
)
|
||||
|
||||
# Extract PR number and URL if available
|
||||
pr_number = None
|
||||
pr_url = None
|
||||
if pr_response and isinstance(pr_response, dict):
|
||||
pr_number = str(pr_response.get('number'))
|
||||
pr_url = pr_response.get('html_url')
|
||||
|
||||
# Store PR information in the database if available
|
||||
if seen_issues_db and issue_text and pr_number and pr_url:
|
||||
seen_issues_db.update_pr_info(issue_text, pr_number, pr_url)
|
||||
logger.info(
|
||||
'Stored PR #%s information for issue #%s', pr_number, issue_number,
|
||||
)
|
||||
|
||||
return True, pr_number, pr_url
|
||||
return True
|
||||
|
||||
|
||||
def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> bool:
|
||||
|
@ -301,9 +283,6 @@ def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool:
|
|||
return result.returncode == 0
|
||||
|
||||
|
||||
SKIP_AIDER = False
|
||||
|
||||
|
||||
def solve_issue_in_repository(
|
||||
args,
|
||||
tmpdirname: Path,
|
||||
|
@ -312,10 +291,7 @@ def solve_issue_in_repository(
|
|||
issue_description: str,
|
||||
issue_number: str,
|
||||
gitea_client=None,
|
||||
seen_issues_db=None,
|
||||
) -> bool:
|
||||
logger.info('### %s #####', issue_title)
|
||||
|
||||
repo_url = f'{args.gitea_url}:{args.owner}/{args.repo}.git'.replace(
|
||||
'https://',
|
||||
'git@',
|
||||
|
@ -344,15 +320,11 @@ def solve_issue_in_repository(
|
|||
|
||||
# Run aider
|
||||
issue_content = f'# {issue_title}\n{issue_description}'
|
||||
if not SKIP_AIDER:
|
||||
succeeded = run_cmd(
|
||||
create_aider_command(issue_content),
|
||||
tmpdirname,
|
||||
check=False,
|
||||
)
|
||||
else:
|
||||
logger.warning('Skipping aider command (for testing)')
|
||||
succeeded = True
|
||||
if not succeeded:
|
||||
logger.error('Aider invocation failed for issue #%s', issue_number)
|
||||
return False
|
||||
|
@ -372,18 +344,15 @@ def solve_issue_in_repository(
|
|||
)
|
||||
files_changed = result.stdout.strip()
|
||||
|
||||
if not files_changed and not SKIP_AIDER:
|
||||
if not files_changed:
|
||||
logger.info(
|
||||
'Aider did not make any changes beyond the initial ruff pass for issue #%s',
|
||||
issue_number,
|
||||
)
|
||||
return False
|
||||
|
||||
# Create issue_text for database tracking
|
||||
issue_text = f'{issue_title}\n{issue_description}'
|
||||
|
||||
# Push changes
|
||||
success, pr_number, pr_url = push_changes(
|
||||
return push_changes(
|
||||
tmpdirname,
|
||||
branch_name,
|
||||
issue_number,
|
||||
|
@ -392,12 +361,8 @@ def solve_issue_in_repository(
|
|||
gitea_client,
|
||||
args.owner,
|
||||
args.repo,
|
||||
seen_issues_db,
|
||||
issue_text,
|
||||
)
|
||||
|
||||
return success
|
||||
|
||||
|
||||
def handle_issues(args, client, seen_issues_db):
|
||||
"""Process all open issues with the 'aider' label.
|
||||
|
@ -436,8 +401,7 @@ def handle_issues(args, client, seen_issues_db):
|
|||
issue_description,
|
||||
issue_number,
|
||||
client,
|
||||
seen_issues_db,
|
||||
)
|
||||
|
||||
if solved:
|
||||
seen_issues_db.mark_as_seen(issue_text, str(issue_number))
|
||||
seen_issues_db.mark_as_seen(issue_text)
|
||||
|
|
|
@ -163,6 +163,7 @@ class GiteaClient:
|
|||
'body': body,
|
||||
'head': head,
|
||||
'base': base,
|
||||
'labels': labels,
|
||||
}
|
||||
|
||||
response = self.session.post(url, json=json_data)
|
||||
|
|
|
@ -3,9 +3,9 @@ import secret_loader
|
|||
SECRETS = secret_loader.SecretLoader()
|
||||
|
||||
|
||||
def llm_api_keys() -> list[str]:
|
||||
return SECRETS.load_or_fail('LLM_API_KEY').strip().split('\n')
|
||||
def llm_api_key():
|
||||
return SECRETS.load_or_fail('LLM_API_KEY')
|
||||
|
||||
|
||||
def gitea_token() -> str:
|
||||
def gitea_token():
|
||||
return SECRETS.load_or_fail('GITEA_TOKEN')
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"""Database module for tracking previously processed issues and pull requests.
|
||||
"""Database module for tracking previously processed issues.
|
||||
|
||||
This module provides functionality to track which issues have already been processed
|
||||
by the system to avoid duplicate processing. It uses a simple SQLite database to
|
||||
store information about seen issues and their associated pull requests for efficient lookup.
|
||||
store hashes of seen issues for efficient lookup.
|
||||
"""
|
||||
|
||||
import sqlite3
|
||||
|
@ -12,12 +12,11 @@ DEFAULT_DB_PATH = 'output/seen_issues.db'
|
|||
|
||||
|
||||
class SeenIssuesDB:
|
||||
"""Database handler for tracking processed issues and pull requests.
|
||||
"""Database handler for tracking processed issues.
|
||||
|
||||
This class manages a SQLite database that stores information about issues that have
|
||||
already been processed and their associated pull requests. It provides methods to mark
|
||||
issues as seen, check if an issue has been seen before, and retrieve pull request
|
||||
information for an issue.
|
||||
This class manages a SQLite database that stores hashes of issues that have
|
||||
already been processed. It provides methods to mark issues as seen and check
|
||||
if an issue has been seen before, helping to prevent duplicate processing.
|
||||
|
||||
Attributes:
|
||||
conn: SQLite database connection
|
||||
|
@ -35,42 +34,29 @@ class SeenIssuesDB:
|
|||
def _create_table(self):
|
||||
"""Create the seen_issues table if it doesn't exist.
|
||||
|
||||
Creates a table with columns for storing issue hashes and associated pull request information.
|
||||
Creates a table with a single column for storing issue hashes.
|
||||
"""
|
||||
with self.conn:
|
||||
self.conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS seen_issues (
|
||||
issue_hash TEXT PRIMARY KEY,
|
||||
issue_number TEXT,
|
||||
pr_number TEXT,
|
||||
pr_url TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
issue_hash TEXT PRIMARY KEY
|
||||
)
|
||||
""")
|
||||
|
||||
def mark_as_seen(
|
||||
self,
|
||||
issue_text: str,
|
||||
issue_number: str = None,
|
||||
pr_number: str = None,
|
||||
pr_url: str = None,
|
||||
):
|
||||
def mark_as_seen(self, issue_text: str):
|
||||
"""Mark an issue as seen in the database.
|
||||
|
||||
Computes a hash of the issue text and stores it in the database along with pull request information.
|
||||
Computes a hash of the issue text and stores it in the database.
|
||||
If the issue has already been marked as seen, this operation has no effect.
|
||||
|
||||
Args:
|
||||
issue_text: The text content of the issue to mark as seen.
|
||||
issue_number: The issue number.
|
||||
pr_number: The pull request number associated with this issue.
|
||||
pr_url: The URL of the pull request associated with this issue.
|
||||
"""
|
||||
issue_hash = self._compute_hash(issue_text)
|
||||
with self.conn:
|
||||
self.conn.execute(
|
||||
'INSERT OR IGNORE INTO seen_issues (issue_hash, issue_number, pr_number, pr_url) VALUES (?, ?, ?, ?)',
|
||||
(issue_hash, issue_number, pr_number, pr_url),
|
||||
'INSERT OR IGNORE INTO seen_issues (issue_hash) VALUES (?)',
|
||||
(issue_hash,),
|
||||
)
|
||||
|
||||
def has_seen(self, issue_text: str) -> bool:
|
||||
|
@ -91,42 +77,6 @@ class SeenIssuesDB:
|
|||
)
|
||||
return cursor.fetchone() is not None
|
||||
|
||||
def get_pr_info(self, issue_text: str) -> tuple[str, str] | None:
|
||||
"""Get pull request information for an issue.
|
||||
|
||||
Args:
|
||||
issue_text: The text content of the issue to check.
|
||||
|
||||
Returns:
|
||||
A tuple containing (pr_number, pr_url) if found, None otherwise.
|
||||
"""
|
||||
issue_hash = self._compute_hash(issue_text)
|
||||
cursor = self.conn.execute(
|
||||
'SELECT pr_number, pr_url FROM seen_issues WHERE issue_hash = ?',
|
||||
(issue_hash,),
|
||||
)
|
||||
result = cursor.fetchone()
|
||||
return result if result else None
|
||||
|
||||
def update_pr_info(self, issue_text: str, pr_number: str, pr_url: str) -> bool:
|
||||
"""Update pull request information for an existing issue.
|
||||
|
||||
Args:
|
||||
issue_text: The text content of the issue to update.
|
||||
pr_number: The pull request number.
|
||||
pr_url: The URL of the pull request.
|
||||
|
||||
Returns:
|
||||
True if the update was successful, False if the issue wasn't found.
|
||||
"""
|
||||
issue_hash = self._compute_hash(issue_text)
|
||||
with self.conn:
|
||||
cursor = self.conn.execute(
|
||||
'UPDATE seen_issues SET pr_number = ?, pr_url = ? WHERE issue_hash = ?',
|
||||
(pr_number, pr_url, issue_hash),
|
||||
)
|
||||
return cursor.rowcount > 0
|
||||
|
||||
def _compute_hash(self, text: str) -> str:
|
||||
"""Compute a SHA-256 hash of the given text.
|
||||
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
import os
|
||||
import tempfile
|
||||
|
||||
from aider_gitea.seen_issues_db import SeenIssuesDB
|
||||
|
||||
|
||||
class TestSeenIssuesDBPRInfo:
|
||||
def setup_method(self):
|
||||
# Create a temporary database file
|
||||
self.db_fd, self.db_path = tempfile.mkstemp()
|
||||
self.db = SeenIssuesDB(self.db_path)
|
||||
|
||||
# Test data
|
||||
self.issue_text = 'Test issue title\nTest issue description'
|
||||
self.issue_number = '123'
|
||||
self.pr_number = '456'
|
||||
self.pr_url = 'https://gitea.example.com/owner/repo/pulls/456'
|
||||
|
||||
def teardown_method(self):
|
||||
# Close and remove the temporary database
|
||||
self.db.conn.close()
|
||||
os.close(self.db_fd)
|
||||
os.unlink(self.db_path)
|
||||
|
||||
def test_mark_as_seen_with_pr_info(self):
|
||||
# Mark an issue as seen with PR info
|
||||
self.db.mark_as_seen(
|
||||
self.issue_text,
|
||||
issue_number=self.issue_number,
|
||||
pr_number=self.pr_number,
|
||||
pr_url=self.pr_url,
|
||||
)
|
||||
|
||||
# Verify the issue is marked as seen
|
||||
assert self.db.has_seen(self.issue_text)
|
||||
|
||||
# Verify PR info is stored correctly
|
||||
pr_info = self.db.get_pr_info(self.issue_text)
|
||||
assert pr_info is not None
|
||||
assert pr_info[0] == self.pr_number
|
||||
assert pr_info[1] == self.pr_url
|
||||
|
||||
def test_update_pr_info(self):
|
||||
# First mark the issue as seen without PR info
|
||||
self.db.mark_as_seen(self.issue_text, issue_number=self.issue_number)
|
||||
|
||||
# Verify no PR info is available
|
||||
assert self.db.get_pr_info(self.issue_text) == (None, None)
|
||||
|
||||
# Update with PR info
|
||||
updated = self.db.update_pr_info(self.issue_text, self.pr_number, self.pr_url)
|
||||
|
||||
# Verify update was successful
|
||||
assert updated
|
||||
|
||||
# Verify PR info is now available
|
||||
pr_info = self.db.get_pr_info(self.issue_text)
|
||||
assert pr_info[0] == self.pr_number
|
||||
assert pr_info[1] == self.pr_url
|
||||
|
||||
def test_update_nonexistent_issue(self):
|
||||
# Try to update PR info for an issue that doesn't exist
|
||||
updated = self.db.update_pr_info(
|
||||
'Nonexistent issue', self.pr_number, self.pr_url,
|
||||
)
|
||||
|
||||
# Verify update failed
|
||||
assert not updated
|
||||
|
||||
def test_get_pr_info_nonexistent(self):
|
||||
# Try to get PR info for an issue that doesn't exist
|
||||
pr_info = self.db.get_pr_info('Nonexistent issue')
|
||||
|
||||
# Verify no PR info is available
|
||||
assert pr_info is None
|
|
@ -19,7 +19,7 @@ class TestSolveIssueInRepository:
|
|||
self.issue_description = 'This is a test issue'
|
||||
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.push_changes')
|
||||
@patch('subprocess.run')
|
||||
|
@ -32,11 +32,7 @@ class TestSolveIssueInRepository:
|
|||
):
|
||||
# Setup mocks
|
||||
mock_run_cmd.return_value = True
|
||||
mock_push_changes.return_value = (
|
||||
True,
|
||||
'456',
|
||||
'https://gitea.example.com/test-owner/test-repo/pulls/456',
|
||||
)
|
||||
mock_push_changes.return_value = True
|
||||
|
||||
# Mock subprocess.run to return different commit hashes and file changes
|
||||
mock_subprocess_run.side_effect = [
|
||||
|
@ -63,7 +59,7 @@ class TestSolveIssueInRepository:
|
|||
assert mock_run_cmd.call_count >= 8 # Verify all expected commands were run
|
||||
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.push_changes')
|
||||
@patch('subprocess.run')
|
||||
|
@ -76,7 +72,6 @@ class TestSolveIssueInRepository:
|
|||
):
|
||||
# Setup mocks
|
||||
mock_run_cmd.return_value = True
|
||||
mock_push_changes.return_value = (False, None, None)
|
||||
|
||||
# Mock subprocess.run to return same commit hash and no file changes
|
||||
mock_subprocess_run.side_effect = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user