Compare commits
1 Commits
924504b618
...
2af894045c
Author | SHA1 | Date | |
---|---|---|---|
2af894045c |
|
@ -792,70 +792,38 @@ def handle_pr_comments(
|
||||||
issue_url,
|
issue_url,
|
||||||
code_solver: CodeSolverStrategy,
|
code_solver: CodeSolverStrategy,
|
||||||
):
|
):
|
||||||
"""Fetch unresolved PR comments and resolve them via code solver.
|
"""Fetch unresolved PR comments and resolve them via code solver."""
|
||||||
|
comments = client.get_pull_request_comments(
|
||||||
This function implements the correct flow:
|
|
||||||
1. Download all reviews of the pull request
|
|
||||||
2. Download all comments for each review
|
|
||||||
3. Fix each comment for each review
|
|
||||||
"""
|
|
||||||
# Download all reviews for the pull request
|
|
||||||
reviews = client.get_pull_request_reviews(
|
|
||||||
repository_config.owner,
|
repository_config.owner,
|
||||||
repository_config.repo,
|
repository_config.repo,
|
||||||
pr_number,
|
pr_number,
|
||||||
)
|
)
|
||||||
|
for comment in comments:
|
||||||
for review in reviews:
|
path = comment.get('path')
|
||||||
review_id = review.get('id')
|
line = comment.get('line') or comment.get('position') or 0
|
||||||
if not review_id:
|
file_path = repository_path / path
|
||||||
continue
|
try:
|
||||||
|
lines = file_path.read_text().splitlines()
|
||||||
# Download all comments for this review
|
start = max(0, line - 3)
|
||||||
comments = client.get_review_comments(
|
end = min(len(lines), line + 2)
|
||||||
repository_config.owner,
|
context = '\n'.join(lines[start:end])
|
||||||
repository_config.repo,
|
except Exception:
|
||||||
pr_number,
|
context = ''
|
||||||
review_id,
|
body = comment.get('body', '')
|
||||||
|
issue = (
|
||||||
|
f'Resolve the following reviewer comment:\n{body}\n\n'
|
||||||
|
f'File: {path}\n\nContext:\n{context}'
|
||||||
)
|
)
|
||||||
|
# invoke code solver on the comment context
|
||||||
# Process each comment in the review
|
code_solver.solve_issue_round(repository_path, issue)
|
||||||
for comment in comments:
|
# commit and push changes for this comment
|
||||||
path = comment.get('path')
|
run_cmd(['git', 'add', path], repository_path, check=False)
|
||||||
line = comment.get('line') or comment.get('position') or 0
|
run_cmd(
|
||||||
if not path:
|
['git', 'commit', '-m', f'Resolve comment {comment.get("id")}'],
|
||||||
continue
|
repository_path,
|
||||||
|
check=False,
|
||||||
file_path = repository_path / path
|
)
|
||||||
try:
|
run_cmd(['git', 'push', 'origin', branch_name], repository_path, check=False)
|
||||||
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 code solver on the comment context
|
|
||||||
code_solver.solve_issue_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 review comment {comment.get("id")}'],
|
|
||||||
repository_path,
|
|
||||||
check=False,
|
|
||||||
)
|
|
||||||
run_cmd(
|
|
||||||
['git', 'push', 'origin', branch_name],
|
|
||||||
repository_path,
|
|
||||||
check=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_failing_pipelines(
|
def handle_failing_pipelines(
|
||||||
|
|
|
@ -219,53 +219,3 @@ class GiteaClient:
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def get_pull_request_reviews(
|
|
||||||
self,
|
|
||||||
owner: str,
|
|
||||||
repo: str,
|
|
||||||
pull_number: int,
|
|
||||||
) -> list[dict]:
|
|
||||||
"""Download all reviews for a pull request.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
owner (str): Owner of the repository.
|
|
||||||
repo (str): Name of the repository.
|
|
||||||
pull_number (int): Pull request number.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list: A list of review dictionaries.
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
requests.HTTPError: If the API request fails.
|
|
||||||
"""
|
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pull_number}/reviews'
|
|
||||||
response = self.session.get(url)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
|
||||||
|
|
||||||
def get_review_comments(
|
|
||||||
self,
|
|
||||||
owner: str,
|
|
||||||
repo: str,
|
|
||||||
pull_number: int,
|
|
||||||
review_id: int,
|
|
||||||
) -> list[dict]:
|
|
||||||
"""Download all comments for a specific review.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
owner (str): Owner of the repository.
|
|
||||||
repo (str): Name of the repository.
|
|
||||||
pull_number (int): Pull request number.
|
|
||||||
review_id (int): Review ID.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list: A list of comment dictionaries.
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
requests.HTTPError: If the API request fails.
|
|
||||||
"""
|
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/comments'
|
|
||||||
response = self.session.get(url)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user