From 80f70b3e2341aef285d994cc5ee2b1839aeebea7 Mon Sep 17 00:00:00 2001 From: Hais Deakin Date: Thu, 18 Dec 2025 13:19:48 +0000 Subject: [PATCH] fix: fallback to issue comment API when PR review comment fetch fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the triggering event is pull_request_review_comment but the actual comment created was a fallback issue comment (due to pending review error), the update-comment-link script would fail with 404 because it only tried the PR review comment API. This change wraps the PR review comment fetch in its own try-catch so it can fall through to try the issue comment API when the PR review comment fetch fails (e.g., 404). This fixes the scenario where: 1. User triggers @cuvvy via PR review comment 2. Initial comment reply fails with "user_id can only have one pending review" 3. Fallback creates an issue comment instead 4. Claude runs successfully 5. update-comment-link fails trying to fetch the issue comment via pulls API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/entrypoints/update-comment-link.ts | 34 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/entrypoints/update-comment-link.ts b/src/entrypoints/update-comment-link.ts index 726527fa1..57dff4b57 100644 --- a/src/entrypoints/update-comment-link.ts +++ b/src/entrypoints/update-comment-link.ts @@ -48,19 +48,31 @@ async function run() { // GitHub has separate ID namespaces for review comments and issue comments // We need to use the correct API based on the event type if (isPullRequestReviewCommentEvent(context)) { - // For PR review comments, use the pulls API - console.log(`Fetching PR review comment ${commentId}`); - const { data: prComment } = await octokit.rest.pulls.getReviewComment({ - owner, - repo, - comment_id: commentId, - }); - comment = prComment; - isPRReviewComment = true; - console.log("Successfully fetched as PR review comment"); + // For PR review comments, try the pulls API first + // But wrap in try-catch because the comment might be a fallback issue comment + // (created when PR review comment reply failed due to pending review) + try { + console.log(`Fetching PR review comment ${commentId}`); + const { data: prComment } = await octokit.rest.pulls.getReviewComment( + { + owner, + repo, + comment_id: commentId, + }, + ); + comment = prComment; + isPRReviewComment = true; + console.log("Successfully fetched as PR review comment"); + } catch (prCommentError) { + // If PR review comment fetch fails (e.g., 404 because it's actually an issue comment), + // fall through to try issue comment API + console.log( + `PR review comment fetch failed (${(prCommentError as Error).message}), will try issue comment API`, + ); + } } - // For all other event types, use the issues API + // For all other event types, or if PR review comment fetch failed, use the issues API if (!comment) { console.log(`Fetching issue comment ${commentId}`); const { data: issueComment } = await octokit.rest.issues.getComment({