mirror of
https://github.com/anomalyco/opencode.git
synced 2026-02-01 22:48:16 +00:00
Revert "feat(github): add ability to react to PR Review Comments in Workflow (#4705)"
This reverts commit 0ce64962d4.
This commit is contained in:
2
.github/workflows/opencode.yml
vendored
2
.github/workflows/opencode.yml
vendored
@@ -3,8 +3,6 @@ name: opencode
|
|||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created]
|
||||||
pull_request_review_comment:
|
|
||||||
types: [created]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
opencode:
|
opencode:
|
||||||
|
|||||||
@@ -30,24 +30,6 @@ Leave the following comment on a GitHub PR. opencode will implement the requeste
|
|||||||
Delete the attachment from S3 when the note is removed /oc
|
Delete the attachment from S3 when the note is removed /oc
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Review specific code lines
|
|
||||||
|
|
||||||
Leave a comment directly on code lines in the PR's "Files" tab. opencode will automatically detect the file, line numbers, and diff context to provide precise responses.
|
|
||||||
|
|
||||||
```
|
|
||||||
[Comment on specific lines in Files tab]
|
|
||||||
/oc add error handling here
|
|
||||||
```
|
|
||||||
|
|
||||||
When commenting on specific lines, opencode receives:
|
|
||||||
|
|
||||||
- The exact file being reviewed
|
|
||||||
- The specific lines of code
|
|
||||||
- The surrounding diff context
|
|
||||||
- Line number information
|
|
||||||
|
|
||||||
This allows for more targeted requests without needing to specify file paths or line numbers manually.
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Run the following command in the terminal from your GitHub repo:
|
Run the following command in the terminal from your GitHub repo:
|
||||||
@@ -69,8 +51,6 @@ This will walk you through installing the GitHub app, creating the workflow, and
|
|||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created]
|
||||||
pull_request_review_comment:
|
|
||||||
types: [created]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
opencode:
|
opencode:
|
||||||
@@ -155,9 +135,3 @@ Replace the image URL `https://github.com/user-attachments/assets/xxxxxxxx` with
|
|||||||
```
|
```
|
||||||
MOCK_EVENT='{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4,"pull_request":{}},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}'
|
MOCK_EVENT='{"eventName":"issue_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"issue":{"number":4,"pull_request":{}},"comment":{"id":1,"body":"hey opencode, summarize thread"}}}'
|
||||||
```
|
```
|
||||||
|
|
||||||
### PR review comment event
|
|
||||||
|
|
||||||
```
|
|
||||||
MOCK_EVENT='{"eventName":"pull_request_review_comment","repo":{"owner":"sst","repo":"hello-world"},"actor":"fwang","payload":{"pull_request":{"number":7},"comment":{"id":1,"body":"hey opencode, add error handling","path":"src/components/Button.tsx","diff_hunk":"@@ -45,8 +45,11 @@\n- const handleClick = () => {\n- console.log('clicked')\n+ const handleClick = useCallback(() => {\n+ console.log('clicked')\n+ doSomething()\n+ }, [doSomething])","line":47,"original_line":45,"position":10,"commit_id":"abc123","original_commit_id":"def456"}}}'
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { graphql } from "@octokit/graphql"
|
|||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as github from "@actions/github"
|
import * as github from "@actions/github"
|
||||||
import type { Context as GitHubContext } from "@actions/github/lib/context"
|
import type { Context as GitHubContext } from "@actions/github/lib/context"
|
||||||
import type { IssueCommentEvent, PullRequestReviewCommentEvent } from "@octokit/webhooks-types"
|
import type { IssueCommentEvent } from "@octokit/webhooks-types"
|
||||||
import { createOpencodeClient } from "@opencode-ai/sdk"
|
import { createOpencodeClient } from "@opencode-ai/sdk"
|
||||||
import { spawn } from "node:child_process"
|
import { spawn } from "node:child_process"
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ let exitCode = 0
|
|||||||
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
|
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertContextEvent("issue_comment", "pull_request_review_comment")
|
assertContextEvent("issue_comment")
|
||||||
assertPayloadKeyword()
|
assertPayloadKeyword()
|
||||||
await assertOpencodeConnected()
|
await assertOpencodeConnected()
|
||||||
|
|
||||||
@@ -241,43 +241,19 @@ function createOpencode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function assertPayloadKeyword() {
|
function assertPayloadKeyword() {
|
||||||
const payload = useContext().payload as IssueCommentEvent | PullRequestReviewCommentEvent
|
const payload = useContext().payload as IssueCommentEvent
|
||||||
const body = payload.comment.body.trim()
|
const body = payload.comment.body.trim()
|
||||||
if (!body.match(/(?:^|\s)(?:\/opencode|\/oc)(?=$|\s)/)) {
|
if (!body.match(/(?:^|\s)(?:\/opencode|\/oc)(?=$|\s)/)) {
|
||||||
throw new Error("Comments must mention `/opencode` or `/oc`")
|
throw new Error("Comments must mention `/opencode` or `/oc`")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReviewCommentContext() {
|
|
||||||
const context = useContext()
|
|
||||||
if (context.eventName !== "pull_request_review_comment") {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const payload = context.payload as PullRequestReviewCommentEvent
|
|
||||||
return {
|
|
||||||
file: payload.comment.path,
|
|
||||||
diffHunk: payload.comment.diff_hunk,
|
|
||||||
line: payload.comment.line,
|
|
||||||
originalLine: payload.comment.original_line,
|
|
||||||
position: payload.comment.position,
|
|
||||||
commitId: payload.comment.commit_id,
|
|
||||||
originalCommitId: payload.comment.original_commit_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function assertOpencodeConnected() {
|
async function assertOpencodeConnected() {
|
||||||
let retry = 0
|
let retry = 0
|
||||||
let connected = false
|
let connected = false
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
await client.app.log<true>({
|
await client.app.get<true>()
|
||||||
body: {
|
|
||||||
service: "github-workflow",
|
|
||||||
level: "info",
|
|
||||||
message: "Prepare to react to Github Workflow event",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
connected = true
|
connected = true
|
||||||
break
|
break
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@@ -407,24 +383,11 @@ async function createComment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getUserPrompt() {
|
async function getUserPrompt() {
|
||||||
const context = useContext()
|
|
||||||
const payload = context.payload as IssueCommentEvent | PullRequestReviewCommentEvent
|
|
||||||
const reviewContext = getReviewCommentContext()
|
|
||||||
|
|
||||||
let prompt = (() => {
|
let prompt = (() => {
|
||||||
|
const payload = useContext().payload as IssueCommentEvent
|
||||||
const body = payload.comment.body.trim()
|
const body = payload.comment.body.trim()
|
||||||
if (body === "/opencode" || body === "/oc") {
|
if (body === "/opencode" || body === "/oc") return "Summarize this thread"
|
||||||
if (reviewContext) {
|
if (body.includes("/opencode") || body.includes("/oc")) return body
|
||||||
return `Review this code change and suggest improvements for the commented lines:\n\nFile: ${reviewContext.file}\nLines: ${reviewContext.line}\n\n${reviewContext.diffHunk}`
|
|
||||||
}
|
|
||||||
return "Summarize this thread"
|
|
||||||
}
|
|
||||||
if (body.includes("/opencode") || body.includes("/oc")) {
|
|
||||||
if (reviewContext) {
|
|
||||||
return `${body}\n\nContext: You are reviewing a comment on file "${reviewContext.file}" at line ${reviewContext.line}.\n\nDiff context:\n${reviewContext.diffHunk}`
|
|
||||||
}
|
|
||||||
return body
|
|
||||||
}
|
|
||||||
throw new Error("Comments must mention `/opencode` or `/oc`")
|
throw new Error("Comments must mention `/opencode` or `/oc`")
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { graphql } from "@octokit/graphql"
|
|||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import * as github from "@actions/github"
|
import * as github from "@actions/github"
|
||||||
import type { Context } from "@actions/github/lib/context"
|
import type { Context } from "@actions/github/lib/context"
|
||||||
import type { IssueCommentEvent, PullRequestReviewCommentEvent } from "@octokit/webhooks-types"
|
import type { IssueCommentEvent } from "@octokit/webhooks-types"
|
||||||
import { UI } from "../ui"
|
import { UI } from "../ui"
|
||||||
import { cmd } from "./cmd"
|
import { cmd } from "./cmd"
|
||||||
import { ModelsDev } from "../../provider/models"
|
import { ModelsDev } from "../../provider/models"
|
||||||
@@ -328,8 +328,6 @@ export const GithubInstallCommand = cmd({
|
|||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created]
|
||||||
pull_request_review_comment:
|
|
||||||
types: [created]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
opencode:
|
opencode:
|
||||||
@@ -380,7 +378,7 @@ export const GithubRunCommand = cmd({
|
|||||||
const isMock = args.token || args.event
|
const isMock = args.token || args.event
|
||||||
|
|
||||||
const context = isMock ? (JSON.parse(args.event!) as Context) : github.context
|
const context = isMock ? (JSON.parse(args.event!) as Context) : github.context
|
||||||
if (context.eventName !== "issue_comment" && context.eventName !== "pull_request_review_comment") {
|
if (context.eventName !== "issue_comment") {
|
||||||
core.setFailed(`Unsupported event type: ${context.eventName}`)
|
core.setFailed(`Unsupported event type: ${context.eventName}`)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
@@ -389,13 +387,9 @@ export const GithubRunCommand = cmd({
|
|||||||
const runId = normalizeRunId()
|
const runId = normalizeRunId()
|
||||||
const share = normalizeShare()
|
const share = normalizeShare()
|
||||||
const { owner, repo } = context.repo
|
const { owner, repo } = context.repo
|
||||||
const payload = context.payload as IssueCommentEvent | PullRequestReviewCommentEvent
|
const payload = context.payload as IssueCommentEvent
|
||||||
const actor = context.actor
|
const actor = context.actor
|
||||||
|
const issueId = payload.issue.number
|
||||||
const issueId =
|
|
||||||
context.eventName === "pull_request_review_comment"
|
|
||||||
? (payload as PullRequestReviewCommentEvent).pull_request.number
|
|
||||||
: (payload as IssueCommentEvent).issue.number
|
|
||||||
const runUrl = `/${owner}/${repo}/actions/runs/${runId}`
|
const runUrl = `/${owner}/${repo}/actions/runs/${runId}`
|
||||||
const shareBaseUrl = isMock ? "https://dev.opencode.ai" : "https://opencode.ai"
|
const shareBaseUrl = isMock ? "https://dev.opencode.ai" : "https://opencode.ai"
|
||||||
|
|
||||||
@@ -537,39 +531,11 @@ export const GithubRunCommand = cmd({
|
|||||||
throw new Error(`Invalid share value: ${value}. Share must be a boolean.`)
|
throw new Error(`Invalid share value: ${value}. Share must be a boolean.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReviewCommentContext() {
|
|
||||||
if (context.eventName !== "pull_request_review_comment") {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const reviewPayload = payload as PullRequestReviewCommentEvent
|
|
||||||
return {
|
|
||||||
file: reviewPayload.comment.path,
|
|
||||||
diffHunk: reviewPayload.comment.diff_hunk,
|
|
||||||
line: reviewPayload.comment.line,
|
|
||||||
originalLine: reviewPayload.comment.original_line,
|
|
||||||
position: reviewPayload.comment.position,
|
|
||||||
commitId: reviewPayload.comment.commit_id,
|
|
||||||
originalCommitId: reviewPayload.comment.original_commit_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getUserPrompt() {
|
async function getUserPrompt() {
|
||||||
const reviewContext = getReviewCommentContext()
|
|
||||||
let prompt = (() => {
|
let prompt = (() => {
|
||||||
const body = payload.comment.body.trim()
|
const body = payload.comment.body.trim()
|
||||||
if (body === "/opencode" || body === "/oc") {
|
if (body === "/opencode" || body === "/oc") return "Summarize this thread"
|
||||||
if (reviewContext) {
|
if (body.includes("/opencode") || body.includes("/oc")) return body
|
||||||
return `Review this code change and suggest improvements for the commented lines:\n\nFile: ${reviewContext.file}\nLines: ${reviewContext.line}\n\n${reviewContext.diffHunk}`
|
|
||||||
}
|
|
||||||
return "Summarize this thread"
|
|
||||||
}
|
|
||||||
if (body.includes("/opencode") || body.includes("/oc")) {
|
|
||||||
if (reviewContext) {
|
|
||||||
return `${body}\n\nContext: You are reviewing a comment on file "${reviewContext.file}" at line ${reviewContext.line}.\n\nDiff context:\n${reviewContext.diffHunk}`
|
|
||||||
}
|
|
||||||
return body
|
|
||||||
}
|
|
||||||
throw new Error("Comments must mention `/opencode` or `/oc`")
|
throw new Error("Comments must mention `/opencode` or `/oc`")
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ Or you can set it up manually.
|
|||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created]
|
||||||
pull_request_review_comment:
|
|
||||||
types: [created]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
opencode:
|
opencode:
|
||||||
@@ -131,20 +129,3 @@ Here are some examples of how you can use opencode in GitHub.
|
|||||||
```
|
```
|
||||||
|
|
||||||
opencode will implement the requested change and commit it to the same PR.
|
opencode will implement the requested change and commit it to the same PR.
|
||||||
|
|
||||||
- **Review specific code lines**
|
|
||||||
|
|
||||||
Leave a comment directly on code lines in the PR's "Files" tab. opencode automatically detects the file, line numbers, and diff context to provide precise responses.
|
|
||||||
|
|
||||||
```
|
|
||||||
[Comment on specific lines in Files tab]
|
|
||||||
/oc add error handling here
|
|
||||||
```
|
|
||||||
|
|
||||||
When commenting on specific lines, opencode receives:
|
|
||||||
- The exact file being reviewed
|
|
||||||
- The specific lines of code
|
|
||||||
- The surrounding diff context
|
|
||||||
- Line number information
|
|
||||||
|
|
||||||
This allows for more targeted requests without needing to specify file paths or line numbers manually.
|
|
||||||
|
|||||||
Reference in New Issue
Block a user