Compare commits
1 Commits
main
...
issue-95-t
Author | SHA1 | Date | |
---|---|---|---|
ccb70d3d47 |
|
@ -103,11 +103,7 @@ class RepositoryConfig:
|
||||||
class IssueResolution:
|
class IssueResolution:
|
||||||
success: bool
|
success: bool
|
||||||
pull_request_url: str | None = None
|
pull_request_url: str | None = None
|
||||||
pull_request_id: int | None = None
|
pull_request_id: str | None = None
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
assert self.pull_request_id is None or isinstance(self.pull_request_id, int)
|
|
||||||
assert self.pull_request_url is None or isinstance(self.pull_request_url, str)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_branch_name(issue_number: str, issue_title: str) -> str:
|
def generate_branch_name(issue_number: str, issue_title: str) -> str:
|
||||||
|
@ -274,6 +270,7 @@ def push_changes(
|
||||||
run_cmd(cmd, cwd)
|
run_cmd(cmd, cwd)
|
||||||
|
|
||||||
# Then create the PR with the aider label
|
# Then create the PR with the aider label
|
||||||
|
try:
|
||||||
pr_response = gitea_client.create_pull_request(
|
pr_response = gitea_client.create_pull_request(
|
||||||
owner=repository_config.owner,
|
owner=repository_config.owner,
|
||||||
repo=repository_config.repo,
|
repo=repository_config.repo,
|
||||||
|
@ -283,12 +280,15 @@ def push_changes(
|
||||||
base=repository_config.base_branch,
|
base=repository_config.base_branch,
|
||||||
labels=['aider'],
|
labels=['aider'],
|
||||||
)
|
)
|
||||||
|
except Exception:
|
||||||
|
logger.exception('Failed to create pull request for issue %s', issue_number)
|
||||||
|
return IssueResolution(False)
|
||||||
|
|
||||||
# Extract PR number and URL if available
|
# Extract PR number and URL if available
|
||||||
return IssueResolution(
|
return IssueResolution(
|
||||||
True,
|
True,
|
||||||
|
str(pr_response.get('number')),
|
||||||
pr_response.get('html_url'),
|
pr_response.get('html_url'),
|
||||||
int(pr_response.get('number')),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -387,9 +387,6 @@ def run_ollama_and_get_yes_or_no(cwd, initial_texts: list[str]) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def verify_solution(repository_path: Path, issue_content: str) -> bool:
|
def verify_solution(repository_path: Path, issue_content: str) -> bool:
|
||||||
if not EVALUATOR_MODEL:
|
|
||||||
return True
|
|
||||||
|
|
||||||
summary = run_ollama(
|
summary = run_ollama(
|
||||||
repository_path,
|
repository_path,
|
||||||
[
|
[
|
||||||
|
@ -509,7 +506,8 @@ def solve_issues_in_repository(
|
||||||
title = issue.get('title', f'Issue {issue_number}')
|
title = issue.get('title', f'Issue {issue_number}')
|
||||||
if seen_issues_db.has_seen(issue_url):
|
if seen_issues_db.has_seen(issue_url):
|
||||||
logger.info('Skipping already processed issue #%s: %s', issue_number, title)
|
logger.info('Skipping already processed issue #%s: %s', issue_number, title)
|
||||||
else:
|
continue
|
||||||
|
|
||||||
branch_name = generate_branch_name(issue_number, title)
|
branch_name = generate_branch_name(issue_number, title)
|
||||||
with tempfile.TemporaryDirectory() as repository_path:
|
with tempfile.TemporaryDirectory() as repository_path:
|
||||||
issue_resolution = solve_issue_in_repository(
|
issue_resolution = solve_issue_in_repository(
|
||||||
|
@ -522,8 +520,7 @@ def solve_issues_in_repository(
|
||||||
client,
|
client,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: PR comment handling disabled for now due to missing functionality
|
if issue_resolution.success:
|
||||||
if False:
|
|
||||||
# Handle unresolved pull request comments
|
# Handle unresolved pull request comments
|
||||||
handle_pr_comments(
|
handle_pr_comments(
|
||||||
repository_config,
|
repository_config,
|
||||||
|
@ -534,15 +531,6 @@ def solve_issues_in_repository(
|
||||||
seen_issues_db,
|
seen_issues_db,
|
||||||
issue_url,
|
issue_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Handle failing pipelines
|
|
||||||
handle_failing_pipelines(
|
|
||||||
repository_config,
|
|
||||||
issue_resolution.pull_request_id,
|
|
||||||
branch_name,
|
|
||||||
Path(repository_path),
|
|
||||||
client,
|
|
||||||
)
|
|
||||||
seen_issues_db.mark_as_seen(issue_url, str(issue_number))
|
seen_issues_db.mark_as_seen(issue_url, str(issue_number))
|
||||||
seen_issues_db.update_pr_info(
|
seen_issues_db.update_pr_info(
|
||||||
issue_url,
|
issue_url,
|
||||||
|
@ -558,7 +546,7 @@ def solve_issues_in_repository(
|
||||||
|
|
||||||
def handle_pr_comments(
|
def handle_pr_comments(
|
||||||
repository_config,
|
repository_config,
|
||||||
pr_number: int,
|
pr_number,
|
||||||
branch_name,
|
branch_name,
|
||||||
repository_path,
|
repository_path,
|
||||||
client,
|
client,
|
||||||
|
@ -597,40 +585,3 @@ def handle_pr_comments(
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
run_cmd(['git', 'push', 'origin', branch_name], repository_path, check=False)
|
run_cmd(['git', 'push', 'origin', branch_name], repository_path, check=False)
|
||||||
|
|
||||||
|
|
||||||
def handle_failing_pipelines(
|
|
||||||
repository_config: RepositoryConfig,
|
|
||||||
pr_number: str,
|
|
||||||
branch_name: str,
|
|
||||||
repository_path: Path,
|
|
||||||
client,
|
|
||||||
) -> None:
|
|
||||||
"""Fetch failing pipelines for the given PR and resolve them via aider."""
|
|
||||||
while True:
|
|
||||||
failed_runs = client.get_failed_pipelines(
|
|
||||||
repository_config.owner,
|
|
||||||
repository_config.repo,
|
|
||||||
pr_number,
|
|
||||||
)
|
|
||||||
if not failed_runs:
|
|
||||||
break
|
|
||||||
for run_id in failed_runs:
|
|
||||||
log = client.get_pipeline_log(
|
|
||||||
repository_config.owner,
|
|
||||||
repository_config.repo,
|
|
||||||
run_id,
|
|
||||||
)
|
|
||||||
lines = log.strip().split('\n')
|
|
||||||
context = '\n'.join(lines[-100:])
|
|
||||||
issue = f'Resolve the following failing pipeline run {run_id}:\n\n{context}'
|
|
||||||
issue_solution_round(repository_path, issue)
|
|
||||||
run_cmd(['git', 'add', '.'], repository_path, check=False)
|
|
||||||
run_cmd(
|
|
||||||
['git', 'commit', '-m', f'Resolve pipeline {run_id}'],
|
|
||||||
repository_path,
|
|
||||||
check=False,
|
|
||||||
)
|
|
||||||
run_cmd(
|
|
||||||
['git', 'push', 'origin', branch_name], repository_path, check=False,
|
|
||||||
)
|
|
||||||
|
|
|
@ -45,16 +45,6 @@ def parse_args():
|
||||||
default=300,
|
default=300,
|
||||||
help='Interval in seconds between checks in daemon mode (default: 300)',
|
help='Interval in seconds between checks in daemon mode (default: 300)',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
|
||||||
'--aider-model',
|
|
||||||
help='Model to use for generating code (overrides default)',
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
'--evaluator-model',
|
|
||||||
help='Model to use for evaluating code (overrides default)',
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,14 +52,6 @@ def main():
|
||||||
logging.basicConfig(level='INFO')
|
logging.basicConfig(level='INFO')
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
# Override default models if provided
|
|
||||||
import aider_gitea as core
|
|
||||||
|
|
||||||
if args.aider_model:
|
|
||||||
core.CODE_MODEL = args.aider_model
|
|
||||||
if args.evaluator_model:
|
|
||||||
core.EVALUATOR_MODEL = args.evaluator_model
|
|
||||||
|
|
||||||
seen_issues_db = SeenIssuesDB()
|
seen_issues_db = SeenIssuesDB()
|
||||||
client = GiteaClient(args.gitea_url, secrets.gitea_token())
|
client = GiteaClient(args.gitea_url, secrets.gitea_token())
|
||||||
|
|
||||||
|
|
|
@ -166,56 +166,19 @@ class GiteaClient:
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.session.post(url, json=json_data)
|
response = self.session.post(url, json=json_data)
|
||||||
# If a pull request for this head/base already exists, return it instead of crashing
|
|
||||||
if response.status_code == 409:
|
|
||||||
logger.warning(
|
|
||||||
'Pull request already exists for head %s and base %s',
|
|
||||||
head,
|
|
||||||
base,
|
|
||||||
)
|
|
||||||
prs = self.get_pull_requests(owner, repo)
|
|
||||||
for pr in prs:
|
|
||||||
if (
|
|
||||||
pr.get('head', {}).get('ref') == head
|
|
||||||
and pr.get('base', {}).get('ref') == base
|
|
||||||
):
|
|
||||||
return pr
|
|
||||||
# fallback to raise if we can’t find it
|
|
||||||
response.raise_for_status()
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def get_failed_pipelines(self, owner: str, repo: str, pr_number: str) -> list[int]:
|
def get_pull_request_comments(
|
||||||
"""Fetch pipeline runs for a PR and return IDs of failed runs."""
|
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs'
|
|
||||||
response = self.session.get(url)
|
|
||||||
response.raise_for_status()
|
|
||||||
runs = response.json().get('workflow_runs', [])
|
|
||||||
failed = []
|
|
||||||
for run in runs:
|
|
||||||
if any(
|
|
||||||
pr.get('number') == int(pr_number)
|
|
||||||
for pr in run.get('pull_requests', [])
|
|
||||||
):
|
|
||||||
if run.get('conclusion') not in ('success',):
|
|
||||||
failed.append(run.get('id'))
|
|
||||||
return failed
|
|
||||||
|
|
||||||
def get_pipeline_log(self, owner: str, repo: str, run_id: int) -> str:
|
|
||||||
"""Download the logs for a pipeline run."""
|
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs/{run_id}/logs'
|
|
||||||
response = self.session.get(url)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.text
|
|
||||||
|
|
||||||
def get_pull_requests(
|
|
||||||
self,
|
self,
|
||||||
owner: str,
|
owner: str,
|
||||||
repo: str,
|
repo: str,
|
||||||
state: str = 'open',
|
pr_number: str,
|
||||||
) -> list[dict]:
|
) -> list[dict]:
|
||||||
"""Fetch pull requests for a repository."""
|
"""
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls?state={state}'
|
Fetch comments for a pull request.
|
||||||
|
"""
|
||||||
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user