Compare commits
2 Commits
74c8e6a197
...
924504b618
Author | SHA1 | Date | |
---|---|---|---|
924504b618 | |||
8f703d601a |
|
@ -794,25 +794,24 @@ def handle_pr_comments(
|
||||||
):
|
):
|
||||||
"""Fetch unresolved PR comments and resolve them via code solver.
|
"""Fetch unresolved PR comments and resolve them via code solver.
|
||||||
|
|
||||||
This function implements the flow:
|
This function implements the correct flow:
|
||||||
1. Download all reviews of the pull request
|
1. Download all reviews of the pull request
|
||||||
2. For each review, download all comments
|
2. Download all comments for each review
|
||||||
3. Fix each comment for each review
|
3. Fix each comment for each review
|
||||||
"""
|
"""
|
||||||
# Step 1: Download all reviews of the pull request
|
# Download all reviews for the pull request
|
||||||
reviews = client.get_pull_request_reviews(
|
reviews = client.get_pull_request_reviews(
|
||||||
repository_config.owner,
|
repository_config.owner,
|
||||||
repository_config.repo,
|
repository_config.repo,
|
||||||
pr_number,
|
pr_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Step 2 & 3: For each review, download all comments and fix them
|
|
||||||
for review in reviews:
|
for review in reviews:
|
||||||
review_id = review.get('id')
|
review_id = review.get('id')
|
||||||
if not review_id:
|
if not review_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get all comments for this review
|
# Download all comments for this review
|
||||||
comments = client.get_review_comments(
|
comments = client.get_review_comments(
|
||||||
repository_config.owner,
|
repository_config.owner,
|
||||||
repository_config.repo,
|
repository_config.repo,
|
||||||
|
@ -820,29 +819,23 @@ def handle_pr_comments(
|
||||||
review_id,
|
review_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Process each comment
|
# Process each comment in the review
|
||||||
for comment in comments:
|
for comment in comments:
|
||||||
path = comment.get('path')
|
path = comment.get('path')
|
||||||
line = comment.get('line') or comment.get('position') or 0
|
line = comment.get('line') or comment.get('position') or 0
|
||||||
file_path = repository_path / path if path else None
|
if not path:
|
||||||
|
continue
|
||||||
|
|
||||||
# Get context around the comment
|
file_path = repository_path / path
|
||||||
try:
|
try:
|
||||||
if file_path and file_path.exists():
|
lines = file_path.read_text().splitlines()
|
||||||
lines = file_path.read_text().splitlines()
|
start = max(0, line - 3)
|
||||||
start = max(0, line - 3)
|
end = min(len(lines), line + 2)
|
||||||
end = min(len(lines), line + 2)
|
context = '\n'.join(lines[start:end])
|
||||||
context = '\n'.join(lines[start:end])
|
|
||||||
else:
|
|
||||||
context = ''
|
|
||||||
except Exception:
|
except Exception:
|
||||||
context = ''
|
context = ''
|
||||||
|
|
||||||
body = comment.get('body', '')
|
body = comment.get('body', '')
|
||||||
if not body:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Create issue description for the code solver
|
|
||||||
issue = (
|
issue = (
|
||||||
f'Resolve the following reviewer comment:\n{body}\n\n'
|
f'Resolve the following reviewer comment:\n{body}\n\n'
|
||||||
f'File: {path}\n\nContext:\n{context}'
|
f'File: {path}\n\nContext:\n{context}'
|
||||||
|
@ -852,11 +845,7 @@ def handle_pr_comments(
|
||||||
code_solver.solve_issue_round(repository_path, issue)
|
code_solver.solve_issue_round(repository_path, issue)
|
||||||
|
|
||||||
# Commit and push changes for this comment
|
# Commit and push changes for this comment
|
||||||
if path:
|
run_cmd(['git', 'add', path], repository_path, check=False)
|
||||||
run_cmd(['git', 'add', path], repository_path, check=False)
|
|
||||||
else:
|
|
||||||
run_cmd(['git', 'add', '.'], repository_path, check=False)
|
|
||||||
|
|
||||||
run_cmd(
|
run_cmd(
|
||||||
['git', 'commit', '-m', f'Resolve review comment {comment.get("id")}'],
|
['git', 'commit', '-m', f'Resolve review comment {comment.get("id")}'],
|
||||||
repository_path,
|
repository_path,
|
||||||
|
|
|
@ -224,22 +224,22 @@ class GiteaClient:
|
||||||
self,
|
self,
|
||||||
owner: str,
|
owner: str,
|
||||||
repo: str,
|
repo: str,
|
||||||
pr_number: int,
|
pull_number: int,
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Get all reviews for a pull request.
|
"""Download all reviews for a pull request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
owner (str): Owner of the repository.
|
owner (str): Owner of the repository.
|
||||||
repo (str): Name of the repository.
|
repo (str): Name of the repository.
|
||||||
pr_number (int): Pull request number.
|
pull_number (int): Pull request number.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[dict]: List of review objects.
|
list: A list of review dictionaries.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
requests.HTTPError: If the API request fails.
|
requests.HTTPError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/reviews'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pull_number}/reviews'
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
@ -248,24 +248,24 @@ class GiteaClient:
|
||||||
self,
|
self,
|
||||||
owner: str,
|
owner: str,
|
||||||
repo: str,
|
repo: str,
|
||||||
pr_number: int,
|
pull_number: int,
|
||||||
review_id: int,
|
review_id: int,
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Get all comments for a specific review.
|
"""Download all comments for a specific review.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
owner (str): Owner of the repository.
|
owner (str): Owner of the repository.
|
||||||
repo (str): Name of the repository.
|
repo (str): Name of the repository.
|
||||||
pr_number (int): Pull request number.
|
pull_number (int): Pull request number.
|
||||||
review_id (int): Review ID.
|
review_id (int): Review ID.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[dict]: List of comment objects.
|
list: A list of comment dictionaries.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
requests.HTTPError: If the API request fails.
|
requests.HTTPError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/reviews/{review_id}/comments'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/comments'
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
|
@ -69,10 +69,9 @@ class TestClaudeCodeIntegration:
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'stream-json',
|
'json',
|
||||||
'--debug',
|
'--max-turns',
|
||||||
'--verbose',
|
'10',
|
||||||
'--dangerously-skip-permissions',
|
|
||||||
issue,
|
issue,
|
||||||
]
|
]
|
||||||
assert cmd == expected
|
assert cmd == expected
|
||||||
|
@ -85,10 +84,9 @@ class TestClaudeCodeIntegration:
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'stream-json',
|
'json',
|
||||||
'--debug',
|
'--max-turns',
|
||||||
'--verbose',
|
'10',
|
||||||
'--dangerously-skip-permissions',
|
|
||||||
'--model',
|
'--model',
|
||||||
'claude-3-sonnet',
|
'claude-3-sonnet',
|
||||||
issue,
|
issue,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user