Skip to content

Commit 31e6ed6

Browse files
authored
Add Eyes Reaction instead of Comment Working on Github Action (#5072)
1 parent da56319 commit 31e6ed6

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

packages/opencode/src/cli/cmd/github.ts

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,12 @@ export const GithubRunCommand = cmd({
403403
let appToken: string
404404
let octoRest: Octokit
405405
let octoGraph: typeof graphql
406-
let commentId: number
407406
let gitConfig: string
408407
let session: { id: string; title: string; version: string }
409408
let shareId: string | undefined
410409
let exitCode = 0
411410
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
411+
const triggerCommentId = payload.comment.id
412412

413413
try {
414414
const actionToken = isMock ? args.token! : await getOidcToken()
@@ -422,8 +422,7 @@ export const GithubRunCommand = cmd({
422422
await configureGit(appToken)
423423
await assertPermissions()
424424

425-
const comment = await createComment()
426-
commentId = comment.data.id
425+
await addReaction("eyes")
427426

428427
// Setup opencode session
429428
const repoData = await fetchRepo()
@@ -455,7 +454,8 @@ export const GithubRunCommand = cmd({
455454
await pushToLocalBranch(summary, uncommittedChanges)
456455
}
457456
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
458-
await updateComment(`${response}${footer({ image: !hasShared })}`)
457+
await createComment(`${response}${footer({ image: !hasShared })}`)
458+
await removeReaction()
459459
}
460460
// Fork PR
461461
else {
@@ -469,7 +469,8 @@ export const GithubRunCommand = cmd({
469469
await pushToForkBranch(summary, prData, uncommittedChanges)
470470
}
471471
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
472-
await updateComment(`${response}${footer({ image: !hasShared })}`)
472+
await createComment(`${response}${footer({ image: !hasShared })}`)
473+
await removeReaction()
473474
}
474475
}
475476
// Issue
@@ -489,9 +490,11 @@ export const GithubRunCommand = cmd({
489490
summary,
490491
`${response}\n\nCloses #${issueId}${footer({ image: true })}`,
491492
)
492-
await updateComment(`Created PR #${pr}${footer({ image: true })}`)
493+
await createComment(`Created PR #${pr}${footer({ image: true })}`)
494+
await removeReaction()
493495
} else {
494-
await updateComment(`${response}${footer({ image: true })}`)
496+
await createComment(`${response}${footer({ image: true })}`)
497+
await removeReaction()
495498
}
496499
}
497500
} catch (e: any) {
@@ -503,7 +506,8 @@ export const GithubRunCommand = cmd({
503506
} else if (e instanceof Error) {
504507
msg = e.message
505508
}
506-
await updateComment(`${msg}${footer()}`)
509+
await createComment(`${msg}${footer()}`)
510+
await removeReaction()
507511
core.setFailed(msg)
508512
// Also output the clean error message for the action to capture
509513
//core.setOutput("prepare_error", e.message);
@@ -931,24 +935,41 @@ Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
931935
if (!["admin", "write"].includes(permission)) throw new Error(`User ${actor} does not have write permissions`)
932936
}
933937

934-
async function createComment() {
935-
console.log("Creating comment...")
936-
return await octoRest.rest.issues.createComment({
938+
async function addReaction(reaction: "eyes") {
939+
console.log("Adding reaction...")
940+
return await octoRest.rest.reactions.createForIssueComment({
937941
owner,
938942
repo,
939-
issue_number: issueId,
940-
body: `[Working...](${runUrl})`,
943+
comment_id: triggerCommentId,
944+
content: reaction,
941945
})
942946
}
943947

944-
async function updateComment(body: string) {
945-
if (!commentId) return
948+
async function removeReaction() {
949+
console.log("Removing reaction...")
950+
const reactions = await octoRest.rest.reactions.listForIssueComment({
951+
owner,
952+
repo,
953+
comment_id: triggerCommentId,
954+
})
955+
956+
const eyesReaction = reactions.data.find((r) => r.content === "eyes")
957+
if (!eyesReaction) return
946958

947-
console.log("Updating comment...")
948-
return await octoRest.rest.issues.updateComment({
959+
await octoRest.rest.reactions.deleteForIssueComment({
949960
owner,
950961
repo,
951-
comment_id: commentId,
962+
comment_id: triggerCommentId,
963+
reaction_id: eyesReaction.id,
964+
})
965+
}
966+
967+
async function createComment(body: string) {
968+
console.log("Creating comment...")
969+
return await octoRest.rest.issues.createComment({
970+
owner,
971+
repo,
972+
issue_number: issueId,
952973
body,
953974
})
954975
}
@@ -1029,7 +1050,7 @@ query($owner: String!, $repo: String!, $number: Int!) {
10291050
const comments = (issue.comments?.nodes || [])
10301051
.filter((c) => {
10311052
const id = parseInt(c.databaseId)
1032-
return id !== commentId && id !== payload.comment.id
1053+
return id !== payload.comment.id
10331054
})
10341055
.map((c) => ` - ${c.author.login} at ${c.createdAt}: ${c.body}`)
10351056

@@ -1148,7 +1169,7 @@ query($owner: String!, $repo: String!, $number: Int!) {
11481169
const comments = (pr.comments?.nodes || [])
11491170
.filter((c) => {
11501171
const id = parseInt(c.databaseId)
1151-
return id !== commentId && id !== payload.comment.id
1172+
return id !== payload.comment.id
11521173
})
11531174
.map((c) => `- ${c.author.login} at ${c.createdAt}: ${c.body}`)
11541175

0 commit comments

Comments
 (0)