Compare commits
2 Commits
0b40e8dec9
...
00678b46e2
Author | SHA1 | Date | |
---|---|---|---|
00678b46e2 | |||
f91f8ad637 |
|
@ -757,8 +757,8 @@ def solve_issues_in_repository(
|
||||||
issue_number,
|
issue_number,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: PR comment handling disabled for now due to missing functionality
|
# Handle unresolved pull request comments
|
||||||
if False:
|
if True:
|
||||||
# Handle unresolved pull request comments
|
# Handle unresolved pull request comments
|
||||||
handle_pr_comments(
|
handle_pr_comments(
|
||||||
repository_config,
|
repository_config,
|
||||||
|
|
|
@ -220,108 +220,89 @@ class GiteaClient:
|
||||||
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]:
|
|
||||||
"""Fetch all reviews for a specific pull request.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
owner (str): Owner of the repository.
|
|
||||||
repo (str): Name of the repository.
|
|
||||||
pull_number (int): Pull request number.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[dict]: 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]:
|
|
||||||
"""Fetch 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[dict]: 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()
|
|
||||||
|
|
||||||
def get_pull_request_comments(
|
def get_pull_request_comments(
|
||||||
self,
|
self,
|
||||||
owner: str,
|
owner: str,
|
||||||
repo: str,
|
repo: str,
|
||||||
pull_number: int,
|
pr_number: int,
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Fetch all comments for a pull request by downloading all reviews and their comments.
|
"""Fetch all review comments for a pull request.
|
||||||
|
|
||||||
This method implements the flow:
|
This method implements the flow:
|
||||||
1. Download all reviews of the pull request
|
1. Download all reviews of the pull request
|
||||||
2. Download all comments for each review
|
2. Download all comments for each review
|
||||||
3. Return all comments from all reviews
|
3. Return all comments in a unified format
|
||||||
|
|
||||||
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.
|
||||||
pull_number (int): Pull request number.
|
pr_number (int): Pull request number.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[dict]: List of all comment dictionaries from all reviews.
|
list[dict]: List of comment dictionaries with keys:
|
||||||
|
- id: Comment ID
|
||||||
Raises:
|
- body: Comment body text
|
||||||
requests.HTTPError: If the API request fails.
|
- path: File path the comment refers to
|
||||||
|
- line: Line number (or position)
|
||||||
|
- user: User who made the comment
|
||||||
"""
|
"""
|
||||||
all_comments = []
|
all_comments = []
|
||||||
|
|
||||||
# Download all reviews of the pull request
|
# First, get all reviews for the pull request
|
||||||
reviews = self.get_pull_request_reviews(owner, repo, pull_number)
|
reviews_url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/reviews'
|
||||||
|
reviews_response = self.session.get(reviews_url)
|
||||||
|
reviews_response.raise_for_status()
|
||||||
|
reviews = reviews_response.json()
|
||||||
|
|
||||||
# Download all comments for each review
|
# For each review, get all comments
|
||||||
for review in reviews:
|
for review in reviews:
|
||||||
review_id = review.get('id')
|
review_id = review.get('id')
|
||||||
if review_id:
|
if not review_id:
|
||||||
try:
|
continue
|
||||||
comments = self.get_review_comments(
|
|
||||||
owner,
|
# Get comments for this specific review
|
||||||
repo,
|
comments_url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/reviews/{review_id}/comments'
|
||||||
pull_number,
|
comments_response = self.session.get(comments_url)
|
||||||
review_id,
|
comments_response.raise_for_status()
|
||||||
|
comments = comments_response.json()
|
||||||
|
|
||||||
|
# Add each comment to our collection
|
||||||
|
all_comments.extend(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'id': comment.get('id'),
|
||||||
|
'body': comment.get('body', ''),
|
||||||
|
'path': comment.get('path', ''),
|
||||||
|
'line': comment.get('line') or comment.get('position') or 0,
|
||||||
|
'user': comment.get('user', {}).get('login', ''),
|
||||||
|
'review_id': review_id,
|
||||||
|
}
|
||||||
|
for comment in comments
|
||||||
|
],
|
||||||
)
|
)
|
||||||
# Add review context to each comment for better debugging
|
|
||||||
for comment in comments:
|
# Also get general PR comments (not tied to specific reviews)
|
||||||
comment['review_id'] = review_id
|
general_comments_url = (
|
||||||
comment['review_state'] = review.get('state')
|
f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/comments'
|
||||||
all_comments.extend(comments)
|
)
|
||||||
except requests.RequestException as e:
|
general_response = self.session.get(general_comments_url)
|
||||||
# Log the error but continue processing other reviews
|
general_response.raise_for_status()
|
||||||
logger.warning(
|
general_comments = general_response.json()
|
||||||
'Failed to get comments for review %s in PR %s: %s',
|
|
||||||
review_id,
|
# Add general comments that have file/line info
|
||||||
pull_number,
|
all_comments.extend(
|
||||||
e,
|
[
|
||||||
|
{
|
||||||
|
'id': comment.get('id'),
|
||||||
|
'body': comment.get('body', ''),
|
||||||
|
'path': comment.get('path', ''),
|
||||||
|
'line': comment.get('line') or comment.get('position') or 0,
|
||||||
|
'user': comment.get('user', {}).get('login', ''),
|
||||||
|
'review_id': None, # General comments don't belong to a specific review
|
||||||
|
}
|
||||||
|
for comment in general_comments
|
||||||
|
if comment.get('path') # Only include comments with file references
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
return all_comments
|
return all_comments
|
||||||
|
|
|
@ -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