From d547cf6ffc40605e20acd58d83ad7e751d3c93e3 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 23 Apr 2025 20:51:10 +0200 Subject: [PATCH 1/5] Initial ruff pass --- aider_gitea/gitea_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aider_gitea/gitea_client.py b/aider_gitea/gitea_client.py index 751b2ea..f1e0cdc 100644 --- a/aider_gitea/gitea_client.py +++ b/aider_gitea/gitea_client.py @@ -169,7 +169,9 @@ class GiteaClient: # If a pull request for this head/base already exists, return it instead of crashing if response.status_code == 422: logger.warning( - 'Pull request already exists for head %s and base %s', head, base, + 'Pull request already exists for head %s and base %s', + head, + base, ) prs = self.get_pull_requests(owner, repo) for pr in prs: -- 2.45.1 From 5371109820437fb2b3dec80fe5289ad26d0d5776 Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Wed, 23 Apr 2025 20:55:09 +0200 Subject: [PATCH 2/5] fix: handle PR comments immediately after resolving all issues without waiting for approval --- aider_gitea/__init__.py | 43 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 4f356a5..764aae0 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -515,29 +515,28 @@ def solve_issues_in_repository( issue_number, client, ) + if issue_resolution.success: + handle_pr_comments( + repository_config, + issue_resolution.pull_request_id, + branch_name, + Path(repository_path), + client, + seen_issues_db, + issue_url, + ) + seen_issues_db.mark_as_seen(issue_url, str(issue_number)) + seen_issues_db.update_pr_info( + issue_url, + issue_resolution.pull_request_id, + issue_resolution.pull_request_url, + ) + logger.info( + 'Stored PR #%s information for issue #%s', + issue_resolution.pull_request_id, + issue_number, + ) - if issue_resolution.success: - # Handle unresolved pull request comments - handle_pr_comments( - repository_config, - issue_resolution.pull_request_id, - branch_name, - Path(repository_path), - client, - seen_issues_db, - issue_url, - ) - seen_issues_db.mark_as_seen(issue_url, str(issue_number)) - seen_issues_db.update_pr_info( - issue_url, - issue_resolution.pull_request_id, - issue_resolution.pull_request_url, - ) - logger.info( - 'Stored PR #%s information for issue #%s', - issue_resolution.pull_request_id, - issue_number, - ) def handle_pr_comments( -- 2.45.1 From 1f64cdb32ed0cc2eaacc83c85a8b9dc8695a2bf1 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 23 Apr 2025 20:55:13 +0200 Subject: [PATCH 3/5] Ruff after aider --- aider_gitea/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 764aae0..28180b9 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -538,7 +538,6 @@ def solve_issues_in_repository( ) - def handle_pr_comments( repository_config, pr_number, -- 2.45.1 From 44b7d148f7486610c4bf92c376085ec381e39eca Mon Sep 17 00:00:00 2001 From: "Jon Michael Aanes (aider)" Date: Wed, 23 Apr 2025 21:28:29 +0200 Subject: [PATCH 4/5] refactor: defer PR comment handling until all issues are resolved and batch process them --- aider_gitea/__init__.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 28180b9..265767e 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -495,6 +495,9 @@ def solve_issues_in_repository( logger.info('No issues found for %s', repository_config.repo) return + # batch up PRs to handle comments after all issues are resolved + jobs: list[tuple[str, str, str]] = [] + for issue in issues: issue_url = issue.get('web_url') issue_number = issue.get('number') @@ -516,15 +519,8 @@ def solve_issues_in_repository( client, ) if issue_resolution.success: - handle_pr_comments( - repository_config, - issue_resolution.pull_request_id, - branch_name, - Path(repository_path), - client, - seen_issues_db, - issue_url, - ) + # defer comment handling until after all issues complete + jobs.append((issue_url, issue_resolution.pull_request_id, branch_name)) seen_issues_db.mark_as_seen(issue_url, str(issue_number)) seen_issues_db.update_pr_info( issue_url, @@ -538,6 +534,21 @@ def solve_issues_in_repository( ) + # once all new issues are done, process any PR comments in batch + for issue_url, pr_id, branch_name in jobs: + with tempfile.TemporaryDirectory() as repository_path: + run_cmd(['git', 'clone', repository_config.repo_url(), repository_path]) + run_cmd(['git', 'checkout', branch_name], repository_path) + handle_pr_comments( + repository_config, + pr_id, + branch_name, + Path(repository_path), + client, + seen_issues_db, + issue_url, + ) + def handle_pr_comments( repository_config, pr_number, -- 2.45.1 From 4c91d624dec2bb636997090b296c2bf8d7ad7b8e Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 23 Apr 2025 21:28:33 +0200 Subject: [PATCH 5/5] Ruff after aider --- aider_gitea/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 265767e..9bd7f24 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -533,7 +533,6 @@ def solve_issues_in_repository( issue_number, ) - # once all new issues are done, process any PR comments in batch for issue_url, pr_id, branch_name in jobs: with tempfile.TemporaryDirectory() as repository_path: @@ -549,6 +548,7 @@ def solve_issues_in_repository( issue_url, ) + def handle_pr_comments( repository_config, pr_number, -- 2.45.1