The open source coding agent.
TypeScript
fix: use correct octokit API for PR review comment reactions (#5778)
Matt Silverlock100c31cbb1ad
diff --git a/packages/opencode/src/cli/cmd/github.ts b/packages/opencode/src/cli/cmd/github.tsindex 027a9be06a0..f4f026d4c3a 100644--- a/packages/opencode/src/cli/cmd/github.ts+++ b/packages/opencode/src/cli/cmd/github.ts@@ -418,6 +418,7 @@ export const GithubRunCommand = cmd({type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]const triggerCommentId = payload.comment.idconst useGithubToken = normalizeUseGithubToken()+ const commentType = context.eventName === "pull_request_review_comment" ? "pr_review" : "issue"try {if (useGithubToken) {@@ -443,7 +444,7 @@ export const GithubRunCommand = cmd({}await assertPermissions()- await addReaction()+ await addReaction(commentType)// Setup opencode sessionconst repoData = await fetchRepo()@@ -476,7 +477,7 @@ export const GithubRunCommand = cmd({}const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))await createComment(`${response}${footer({ image: !hasShared })}`)- await removeReaction()+ await removeReaction(commentType)}// Fork PRelse {@@ -491,7 +492,7 @@ export const GithubRunCommand = cmd({}const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))await createComment(`${response}${footer({ image: !hasShared })}`)- await removeReaction()+ await removeReaction(commentType)}}// Issue@@ -512,10 +513,10 @@ export const GithubRunCommand = cmd({`${response}\n\nCloses #${issueId}${footer({ image: true })}`,)await createComment(`Created PR #${pr}${footer({ image: true })}`)- await removeReaction()+ await removeReaction(commentType)} else {await createComment(`${response}${footer({ image: true })}`)- await removeReaction()+ await removeReaction(commentType)}}} catch (e: any) {@@ -528,7 +529,7 @@ export const GithubRunCommand = cmd({msg = e.message}await createComment(`${msg}${footer()}`)- await removeReaction()+ await removeReaction(commentType)core.setFailed(msg)// Also output the clean error message for the action to capture//core.setOutput("prepare_error", e.message);@@ -977,8 +978,16 @@ Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`if (!["admin", "write"].includes(permission)) throw new Error(`User ${actor} does not have write permissions`)}- async function addReaction() {+ async function addReaction(commentType: "issue" | "pr_review") {console.log("Adding reaction...")+ if (commentType === "pr_review") {+ return await octoRest.rest.reactions.createForPullRequestReviewComment({+ owner,+ repo,+ comment_id: triggerCommentId,+ content: AGENT_REACTION,+ })+ }return await octoRest.rest.reactions.createForIssueComment({owner,repo,@@ -987,8 +996,28 @@ Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`})}- async function removeReaction() {+ async function removeReaction(commentType: "issue" | "pr_review") {console.log("Removing reaction...")+ if (commentType === "pr_review") {+ const reactions = await octoRest.rest.reactions.listForPullRequestReviewComment({+ owner,+ repo,+ comment_id: triggerCommentId,+ content: AGENT_REACTION,+ })++ const eyesReaction = reactions.data.find((r) => r.user?.login === AGENT_USERNAME)+ if (!eyesReaction) return++ await octoRest.rest.reactions.deleteForPullRequestComment({+ owner,+ repo,+ comment_id: triggerCommentId,+ reaction_id: eyesReaction.id,+ })+ return+ }+const reactions = await octoRest.rest.reactions.listForIssueComment({owner,repo,