Skip to content

Commit 80f70b3

Browse files
Haisclaude
andcommitted
fix: fallback to issue comment API when PR review comment fetch fails
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 <noreply@anthropic.com>
1 parent d0b730a commit 80f70b3

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

src/entrypoints/update-comment-link.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,31 @@ async function run() {
4848
// GitHub has separate ID namespaces for review comments and issue comments
4949
// We need to use the correct API based on the event type
5050
if (isPullRequestReviewCommentEvent(context)) {
51-
// For PR review comments, use the pulls API
52-
console.log(`Fetching PR review comment ${commentId}`);
53-
const { data: prComment } = await octokit.rest.pulls.getReviewComment({
54-
owner,
55-
repo,
56-
comment_id: commentId,
57-
});
58-
comment = prComment;
59-
isPRReviewComment = true;
60-
console.log("Successfully fetched as PR review comment");
51+
// For PR review comments, try the pulls API first
52+
// But wrap in try-catch because the comment might be a fallback issue comment
53+
// (created when PR review comment reply failed due to pending review)
54+
try {
55+
console.log(`Fetching PR review comment ${commentId}`);
56+
const { data: prComment } = await octokit.rest.pulls.getReviewComment(
57+
{
58+
owner,
59+
repo,
60+
comment_id: commentId,
61+
},
62+
);
63+
comment = prComment;
64+
isPRReviewComment = true;
65+
console.log("Successfully fetched as PR review comment");
66+
} catch (prCommentError) {
67+
// If PR review comment fetch fails (e.g., 404 because it's actually an issue comment),
68+
// fall through to try issue comment API
69+
console.log(
70+
`PR review comment fetch failed (${(prCommentError as Error).message}), will try issue comment API`,
71+
);
72+
}
6173
}
6274

63-
// For all other event types, use the issues API
75+
// For all other event types, or if PR review comment fetch failed, use the issues API
6476
if (!comment) {
6577
console.log(`Fetching issue comment ${commentId}`);
6678
const { data: issueComment } = await octokit.rest.issues.getComment({

0 commit comments

Comments
 (0)