Compare commits
2 Commits
69732c77b0
...
74c8e6a197
Author | SHA1 | Date | |
---|---|---|---|
74c8e6a197 | |||
1a80758d7e |
|
@ -368,9 +368,11 @@ class ClaudeCodeSolver(CodeSolverStrategy):
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'json',
|
'stream-json',
|
||||||
'--max-turns',
|
#'--max-turns', '100',
|
||||||
'10',
|
'--debug',
|
||||||
|
'--verbose',
|
||||||
|
'--dangerously-skip-permissions',
|
||||||
]
|
]
|
||||||
|
|
||||||
if CODE_MODEL:
|
if CODE_MODEL:
|
||||||
|
@ -790,38 +792,81 @@ 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 flow:
|
||||||
|
1. Download all reviews of the pull request
|
||||||
|
2. For each review, download all comments
|
||||||
|
3. Fix each comment for each review
|
||||||
|
"""
|
||||||
|
# Step 1: Download all reviews of 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:
|
|
||||||
path = comment.get('path')
|
# Step 2 & 3: For each review, download all comments and fix them
|
||||||
line = comment.get('line') or comment.get('position') or 0
|
for review in reviews:
|
||||||
file_path = repository_path / path
|
review_id = review.get('id')
|
||||||
try:
|
if not review_id:
|
||||||
lines = file_path.read_text().splitlines()
|
continue
|
||||||
start = max(0, line - 3)
|
|
||||||
end = min(len(lines), line + 2)
|
# Get all comments for this review
|
||||||
context = '\n'.join(lines[start:end])
|
comments = client.get_review_comments(
|
||||||
except Exception:
|
repository_config.owner,
|
||||||
context = ''
|
repository_config.repo,
|
||||||
body = comment.get('body', '')
|
pr_number,
|
||||||
issue = (
|
review_id,
|
||||||
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)
|
# Process each comment
|
||||||
# commit and push changes for this comment
|
for comment in comments:
|
||||||
run_cmd(['git', 'add', path], repository_path, check=False)
|
path = comment.get('path')
|
||||||
run_cmd(
|
line = comment.get('line') or comment.get('position') or 0
|
||||||
['git', 'commit', '-m', f'Resolve comment {comment.get("id")}'],
|
file_path = repository_path / path if path else None
|
||||||
repository_path,
|
|
||||||
check=False,
|
# Get context around the comment
|
||||||
)
|
try:
|
||||||
run_cmd(['git', 'push', 'origin', branch_name], repository_path, check=False)
|
if file_path and file_path.exists():
|
||||||
|
lines = file_path.read_text().splitlines()
|
||||||
|
start = max(0, line - 3)
|
||||||
|
end = min(len(lines), line + 2)
|
||||||
|
context = '\n'.join(lines[start:end])
|
||||||
|
else:
|
||||||
|
context = ''
|
||||||
|
except Exception:
|
||||||
|
context = ''
|
||||||
|
|
||||||
|
body = comment.get('body', '')
|
||||||
|
if not body:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Create issue description for the code solver
|
||||||
|
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
|
||||||
|
if path:
|
||||||
|
run_cmd(['git', 'add', path], repository_path, check=False)
|
||||||
|
else:
|
||||||
|
run_cmd(['git', 'add', '.'], 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(
|
||||||
|
|
|
@ -15,12 +15,10 @@ class GiteaClient:
|
||||||
Read more about the Gitea API here: https://gitea.com/api/swagger
|
Read more about the Gitea API here: https://gitea.com/api/swagger
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
ROOT_URL (str): The base URL for the Gitea API endpoints.
|
gitea_url (str): The base URL for the Gitea API endpoints.
|
||||||
session (requests.Session): HTTP session for making API requests.
|
session (requests.Session): HTTP session for making API requests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ROOT_URL = None
|
|
||||||
|
|
||||||
def __init__(self, gitea_url: str, token: str) -> None:
|
def __init__(self, gitea_url: str, token: str) -> None:
|
||||||
"""Initialize a new Gitea API client.
|
"""Initialize a new Gitea API client.
|
||||||
|
|
||||||
|
@ -32,7 +30,7 @@ class GiteaClient:
|
||||||
AssertionError: If gitea_url ends with '/api/v1'.
|
AssertionError: If gitea_url ends with '/api/v1'.
|
||||||
"""
|
"""
|
||||||
assert not gitea_url.endswith('/api/v1')
|
assert not gitea_url.endswith('/api/v1')
|
||||||
self.ROOT_URL = gitea_url + '/api/v1'
|
self.gitea_url = gitea_url + '/api/v1'
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.headers['Content-Type'] = 'application/json'
|
self.session.headers['Content-Type'] = 'application/json'
|
||||||
if token:
|
if token:
|
||||||
|
@ -52,7 +50,7 @@ class GiteaClient:
|
||||||
Raises:
|
Raises:
|
||||||
requests.HTTPError: If the API request fails.
|
requests.HTTPError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/branches/{branch}'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/branches/{branch}'
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
@ -73,7 +71,7 @@ class GiteaClient:
|
||||||
Raises:
|
Raises:
|
||||||
requests.HTTPError: If the API request fails for reasons other than branch already existing.
|
requests.HTTPError: If the API request fails for reasons other than branch already existing.
|
||||||
"""
|
"""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/git/refs'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/git/refs'
|
||||||
json_data = {'ref': f'refs/heads/{new_branch}', 'sha': sha}
|
json_data = {'ref': f'refs/heads/{new_branch}', 'sha': sha}
|
||||||
response = self.session.post(url, json=json_data)
|
response = self.session.post(url, json=json_data)
|
||||||
if response.status_code == 422:
|
if response.status_code == 422:
|
||||||
|
@ -95,7 +93,7 @@ class GiteaClient:
|
||||||
Raises:
|
Raises:
|
||||||
requests.HTTPError: If the API request fails.
|
requests.HTTPError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/issues'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/issues'
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
issues = response.json()
|
issues = response.json()
|
||||||
|
@ -121,7 +119,7 @@ class GiteaClient:
|
||||||
Returns:
|
Returns:
|
||||||
Iterator[str]: An iterator of repository names.
|
Iterator[str]: An iterator of repository names.
|
||||||
"""
|
"""
|
||||||
url = f'{self.ROOT_URL}/user/repos'
|
url = f'{self.gitea_url}/user/repos'
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
|
@ -159,7 +157,7 @@ class GiteaClient:
|
||||||
Raises:
|
Raises:
|
||||||
requests.HTTPError: If the API request fails.
|
requests.HTTPError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/pulls'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls'
|
||||||
json_data = {
|
json_data = {
|
||||||
'title': title,
|
'title': title,
|
||||||
'body': body,
|
'body': body,
|
||||||
|
@ -189,7 +187,7 @@ class GiteaClient:
|
||||||
|
|
||||||
def get_failed_pipelines(self, owner: str, repo: str, pr_number: str) -> list[int]:
|
def get_failed_pipelines(self, owner: str, repo: str, pr_number: str) -> list[int]:
|
||||||
"""Fetch pipeline runs for a PR and return IDs of failed runs."""
|
"""Fetch pipeline runs for a PR and return IDs of failed runs."""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/actions/runs'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs'
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
runs = response.json().get('workflow_runs', [])
|
runs = response.json().get('workflow_runs', [])
|
||||||
|
@ -205,7 +203,7 @@ class GiteaClient:
|
||||||
|
|
||||||
def get_pipeline_log(self, owner: str, repo: str, run_id: int) -> str:
|
def get_pipeline_log(self, owner: str, repo: str, run_id: int) -> str:
|
||||||
"""Download the logs for a pipeline run."""
|
"""Download the logs for a pipeline run."""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/actions/runs/{run_id}/logs'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs/{run_id}/logs'
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.text
|
return response.text
|
||||||
|
@ -217,7 +215,7 @@ class GiteaClient:
|
||||||
state: str = 'open',
|
state: str = 'open',
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Fetch pull requests for a repository."""
|
"""Fetch pull requests for a repository."""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/pulls?state={state}'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls?state={state}'
|
||||||
response = self.session.get(url)
|
response = self.session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
@ -228,7 +226,7 @@ class GiteaClient:
|
||||||
repo: str,
|
repo: str,
|
||||||
pr_number: int,
|
pr_number: int,
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Download all reviews of a pull request.
|
"""Get all reviews for a pull request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
owner (str): Owner of the repository.
|
owner (str): Owner of the repository.
|
||||||
|
@ -236,12 +234,12 @@ class GiteaClient:
|
||||||
pr_number (int): Pull request number.
|
pr_number (int): Pull request number.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[dict]: A list of review dictionaries.
|
list[dict]: List of review objects.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
requests.HTTPError: If the API request fails.
|
requests.HTTPError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/pulls/{pr_number}/reviews'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_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()
|
||||||
|
@ -253,7 +251,7 @@ class GiteaClient:
|
||||||
pr_number: int,
|
pr_number: int,
|
||||||
review_id: int,
|
review_id: int,
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Download all comments for a specific review.
|
"""Get all comments for a specific review.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
owner (str): Owner of the repository.
|
owner (str): Owner of the repository.
|
||||||
|
@ -262,67 +260,12 @@ class GiteaClient:
|
||||||
review_id (int): Review ID.
|
review_id (int): Review ID.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[dict]: A list of review comment dictionaries.
|
list[dict]: List of comment objects.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
requests.HTTPError: If the API request fails.
|
requests.HTTPError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
url = f'{self.ROOT_URL}/repos/{owner}/{repo}/pulls/{pr_number}/reviews/{review_id}/comments'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_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()
|
||||||
|
|
||||||
def get_pull_request_comments(
|
|
||||||
self,
|
|
||||||
owner: str,
|
|
||||||
repo: str,
|
|
||||||
pr_number: int,
|
|
||||||
) -> list[dict]:
|
|
||||||
"""Download all review comments for a pull request by iterating through all reviews.
|
|
||||||
|
|
||||||
This method implements the proper flow:
|
|
||||||
1. Download all reviews of the pull request
|
|
||||||
2. Download all comments for each review
|
|
||||||
3. Return all comments combined
|
|
||||||
|
|
||||||
Args:
|
|
||||||
owner (str): Owner of the repository.
|
|
||||||
repo (str): Name of the repository.
|
|
||||||
pr_number (int): Pull request number.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[dict]: A list of all review comment dictionaries.
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
requests.HTTPError: If the API request fails.
|
|
||||||
"""
|
|
||||||
all_comments = []
|
|
||||||
|
|
||||||
# Step 1: Download all reviews of the pull request
|
|
||||||
reviews = self.get_pull_request_reviews(owner, repo, pr_number)
|
|
||||||
|
|
||||||
# Step 2: Download all comments for each review
|
|
||||||
for review in reviews:
|
|
||||||
review_id = review.get('id')
|
|
||||||
if review_id:
|
|
||||||
try:
|
|
||||||
comments = self.get_review_comments(
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
pr_number,
|
|
||||||
review_id,
|
|
||||||
)
|
|
||||||
# Add review context to each comment
|
|
||||||
for comment in comments:
|
|
||||||
comment['review_id'] = review_id
|
|
||||||
comment['review_state'] = review.get('state')
|
|
||||||
all_comments.extend(comments)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(
|
|
||||||
'Failed to get comments for review %s: %s',
|
|
||||||
review_id,
|
|
||||||
e,
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
|
|
||||||
return all_comments
|
|
||||||
|
|
|
@ -69,9 +69,10 @@ class TestClaudeCodeIntegration:
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'json',
|
'stream-json',
|
||||||
'--max-turns',
|
'--debug',
|
||||||
'10',
|
'--verbose',
|
||||||
|
'--dangerously-skip-permissions',
|
||||||
issue,
|
issue,
|
||||||
]
|
]
|
||||||
assert cmd == expected
|
assert cmd == expected
|
||||||
|
@ -84,9 +85,10 @@ class TestClaudeCodeIntegration:
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'json',
|
'stream-json',
|
||||||
'--max-turns',
|
'--debug',
|
||||||
'10',
|
'--verbose',
|
||||||
|
'--dangerously-skip-permissions',
|
||||||
'--model',
|
'--model',
|
||||||
'claude-3-sonnet',
|
'claude-3-sonnet',
|
||||||
issue,
|
issue,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user