Handle pull request comments #89
|
@ -80,6 +80,7 @@ from pathlib import Path
|
|||
|
||||
from . import secrets
|
||||
from ._version import __version__ # noqa: F401
|
||||
from .seen_issues_db import SeenIssuesDB
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -516,6 +517,16 @@ def solve_issues_in_repository(
|
|||
)
|
||||
|
||||
if issue_resolution.success:
|
||||
# Handle unresolved pull request comments
|
||||
handle_pr_comments(
|
||||
repository_config,
|
||||
issue_resolution.pull_request_id,
|
||||
branch_name,
|
||||
Path(repository_path),
|
||||
client,
|
||||
seen_issues_db,
|
||||
issue_url,
|
||||
)
|
||||
seen_issues_db.mark_as_seen(issue_url, str(issue_number))
|
||||
seen_issues_db.update_pr_info(
|
||||
issue_url,
|
||||
|
@ -527,3 +538,46 @@ def solve_issues_in_repository(
|
|||
issue_resolution.pull_request_id,
|
||||
issue_number,
|
||||
)
|
||||
|
||||
|
||||
def handle_pr_comments(
|
||||
repository_config,
|
||||
pr_number,
|
||||
branch_name,
|
||||
repository_path,
|
||||
client,
|
||||
seen_issues_db,
|
||||
issue_url,
|
||||
):
|
||||
"""Fetch unresolved PR comments and resolve them via aider."""
|
||||
comments = client.get_pull_request_comments(
|
||||
repository_config.owner,
|
||||
repository_config.repo,
|
||||
pr_number,
|
||||
)
|
||||
for comment in comments:
|
||||
path = comment.get('path')
|
||||
line = comment.get('line') or comment.get('position') or 0
|
||||
file_path = repository_path / path
|
||||
try:
|
||||
lines = file_path.read_text().splitlines()
|
||||
start = max(0, line - 3)
|
||||
end = min(len(lines), line + 2)
|
||||
context = '\n'.join(lines[start:end])
|
||||
except Exception:
|
||||
context = ''
|
||||
body = comment.get('body', '')
|
||||
issue = (
|
||||
f'Resolve the following reviewer comment:\n{body}\n\n'
|
||||
f'File: {path}\n\nContext:\n{context}'
|
||||
)
|
||||
# invoke aider on the comment context
|
||||
issue_solution_round(repository_path, issue)
|
||||
# commit and push changes for this comment
|
||||
run_cmd(['git', 'add', path], repository_path, check=False)
|
||||
run_cmd(
|
||||
['git', 'commit', '-m', f'Resolve comment {comment.get("id")}'],
|
||||
repository_path,
|
||||
check=False,
|
||||
)
|
||||
run_cmd(['git', 'push', 'origin', branch_name], repository_path, check=False)
|
||||
|
|
|
@ -168,3 +168,17 @@ class GiteaClient:
|
|||
response = self.session.post(url, json=json_data)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def get_pull_request_comments(
|
||||
self,
|
||||
owner: str,
|
||||
repo: str,
|
||||
pr_number: str,
|
||||
) -> list[dict]:
|
||||
"""
|
||||
Fetch comments for a pull request.
|
||||
"""
|
||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/comments'
|
||||
response = self.session.get(url)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
|
|
@ -46,6 +46,13 @@ class SeenIssuesDB:
|
|||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
self.conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS resolved_comments (
|
||||
issue_url TEXT,
|
||||
comment_id TEXT,
|
||||
PRIMARY KEY(issue_url, comment_id)
|
||||
)
|
||||
""")
|
||||
|
||||
def mark_as_seen(
|
||||
self,
|
||||
|
|
Loading…
Reference in New Issue
Block a user