Handle pull request comments only after having handled all unresollved issues. #103

Closed
Jmaa wants to merge 5 commits from issue-102-handle-pull-request-comments-only-after-having-handled-all-unresollved-issues into main
2 changed files with 26 additions and 15 deletions

View File

@ -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')
@ -515,29 +518,35 @@ def solve_issues_in_repository(
issue_number,
client,
)
if issue_resolution.success:
# 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,
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
# 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,
issue_resolution.pull_request_id,
pr_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(

View File

@ -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: