mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Add Eyes Reaction instead of Comment Working on Github Action (#5072)
Some checks are pending
deploy / deploy (push) Waiting to run
generate / generate (push) Waiting to run
publish / publish (push) Waiting to run
publish / publish-tauri (map[host:macos-latest target:aarch64-apple-darwin]) (push) Waiting to run
publish / publish-tauri (map[host:macos-latest target:x86_64-apple-darwin]) (push) Waiting to run
publish / publish-tauri (map[host:ubuntu-24.04 target:x86_64-unknown-linux-gnu]) (push) Waiting to run
publish / publish-tauri (map[host:windows-latest target:x86_64-pc-windows-msvc]) (push) Waiting to run
test / test (push) Waiting to run
Update Nix Hashes / update (push) Waiting to run
Some checks are pending
deploy / deploy (push) Waiting to run
generate / generate (push) Waiting to run
publish / publish (push) Waiting to run
publish / publish-tauri (map[host:macos-latest target:aarch64-apple-darwin]) (push) Waiting to run
publish / publish-tauri (map[host:macos-latest target:x86_64-apple-darwin]) (push) Waiting to run
publish / publish-tauri (map[host:ubuntu-24.04 target:x86_64-unknown-linux-gnu]) (push) Waiting to run
publish / publish-tauri (map[host:windows-latest target:x86_64-pc-windows-msvc]) (push) Waiting to run
test / test (push) Waiting to run
Update Nix Hashes / update (push) Waiting to run
This commit is contained in:
parent
da56319af4
commit
31e6ed6806
1 changed files with 44 additions and 23 deletions
|
|
@ -403,12 +403,12 @@ export const GithubRunCommand = cmd({
|
|||
let appToken: string
|
||||
let octoRest: Octokit
|
||||
let octoGraph: typeof graphql
|
||||
let commentId: number
|
||||
let gitConfig: string
|
||||
let session: { id: string; title: string; version: string }
|
||||
let shareId: string | undefined
|
||||
let exitCode = 0
|
||||
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
|
||||
const triggerCommentId = payload.comment.id
|
||||
|
||||
try {
|
||||
const actionToken = isMock ? args.token! : await getOidcToken()
|
||||
|
|
@ -422,8 +422,7 @@ export const GithubRunCommand = cmd({
|
|||
await configureGit(appToken)
|
||||
await assertPermissions()
|
||||
|
||||
const comment = await createComment()
|
||||
commentId = comment.data.id
|
||||
await addReaction("eyes")
|
||||
|
||||
// Setup opencode session
|
||||
const repoData = await fetchRepo()
|
||||
|
|
@ -455,7 +454,8 @@ export const GithubRunCommand = cmd({
|
|||
await pushToLocalBranch(summary, uncommittedChanges)
|
||||
}
|
||||
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
|
||||
await updateComment(`${response}${footer({ image: !hasShared })}`)
|
||||
await createComment(`${response}${footer({ image: !hasShared })}`)
|
||||
await removeReaction()
|
||||
}
|
||||
// Fork PR
|
||||
else {
|
||||
|
|
@ -469,7 +469,8 @@ export const GithubRunCommand = cmd({
|
|||
await pushToForkBranch(summary, prData, uncommittedChanges)
|
||||
}
|
||||
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
|
||||
await updateComment(`${response}${footer({ image: !hasShared })}`)
|
||||
await createComment(`${response}${footer({ image: !hasShared })}`)
|
||||
await removeReaction()
|
||||
}
|
||||
}
|
||||
// Issue
|
||||
|
|
@ -489,9 +490,11 @@ export const GithubRunCommand = cmd({
|
|||
summary,
|
||||
`${response}\n\nCloses #${issueId}${footer({ image: true })}`,
|
||||
)
|
||||
await updateComment(`Created PR #${pr}${footer({ image: true })}`)
|
||||
await createComment(`Created PR #${pr}${footer({ image: true })}`)
|
||||
await removeReaction()
|
||||
} else {
|
||||
await updateComment(`${response}${footer({ image: true })}`)
|
||||
await createComment(`${response}${footer({ image: true })}`)
|
||||
await removeReaction()
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
|
|
@ -503,7 +506,8 @@ export const GithubRunCommand = cmd({
|
|||
} else if (e instanceof Error) {
|
||||
msg = e.message
|
||||
}
|
||||
await updateComment(`${msg}${footer()}`)
|
||||
await createComment(`${msg}${footer()}`)
|
||||
await removeReaction()
|
||||
core.setFailed(msg)
|
||||
// Also output the clean error message for the action to capture
|
||||
//core.setOutput("prepare_error", e.message);
|
||||
|
|
@ -931,24 +935,41 @@ 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 createComment() {
|
||||
async function addReaction(reaction: "eyes") {
|
||||
console.log("Adding reaction...")
|
||||
return await octoRest.rest.reactions.createForIssueComment({
|
||||
owner,
|
||||
repo,
|
||||
comment_id: triggerCommentId,
|
||||
content: reaction,
|
||||
})
|
||||
}
|
||||
|
||||
async function removeReaction() {
|
||||
console.log("Removing reaction...")
|
||||
const reactions = await octoRest.rest.reactions.listForIssueComment({
|
||||
owner,
|
||||
repo,
|
||||
comment_id: triggerCommentId,
|
||||
})
|
||||
|
||||
const eyesReaction = reactions.data.find((r) => r.content === "eyes")
|
||||
if (!eyesReaction) return
|
||||
|
||||
await octoRest.rest.reactions.deleteForIssueComment({
|
||||
owner,
|
||||
repo,
|
||||
comment_id: triggerCommentId,
|
||||
reaction_id: eyesReaction.id,
|
||||
})
|
||||
}
|
||||
|
||||
async function createComment(body: string) {
|
||||
console.log("Creating comment...")
|
||||
return await octoRest.rest.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueId,
|
||||
body: `[Working...](${runUrl})`,
|
||||
})
|
||||
}
|
||||
|
||||
async function updateComment(body: string) {
|
||||
if (!commentId) return
|
||||
|
||||
console.log("Updating comment...")
|
||||
return await octoRest.rest.issues.updateComment({
|
||||
owner,
|
||||
repo,
|
||||
comment_id: commentId,
|
||||
body,
|
||||
})
|
||||
}
|
||||
|
|
@ -1029,7 +1050,7 @@ query($owner: String!, $repo: String!, $number: Int!) {
|
|||
const comments = (issue.comments?.nodes || [])
|
||||
.filter((c) => {
|
||||
const id = parseInt(c.databaseId)
|
||||
return id !== commentId && id !== payload.comment.id
|
||||
return id !== payload.comment.id
|
||||
})
|
||||
.map((c) => ` - ${c.author.login} at ${c.createdAt}: ${c.body}`)
|
||||
|
||||
|
|
@ -1148,7 +1169,7 @@ query($owner: String!, $repo: String!, $number: Int!) {
|
|||
const comments = (pr.comments?.nodes || [])
|
||||
.filter((c) => {
|
||||
const id = parseInt(c.databaseId)
|
||||
return id !== commentId && id !== payload.comment.id
|
||||
return id !== payload.comment.id
|
||||
})
|
||||
.map((c) => `- ${c.author.login} at ${c.createdAt}: ${c.body}`)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue