Skip to content

Commit e1cc98d

Browse files
committed
Revert "feat(github): add ability to react to PR Review Comments in Workflow (anomalyco#4705)"
This reverts commit 0ce6496.
1 parent 0ce6496 commit e1cc98d

File tree

5 files changed

+13
-131
lines changed

5 files changed

+13
-131
lines changed

.github/workflows/opencode.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: opencode
33
on:
44
issue_comment:
55
types: [created]
6-
pull_request_review_comment:
7-
types: [created]
86

97
jobs:
108
opencode:

github/README.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,6 @@ Leave the following comment on a GitHub PR. opencode will implement the requeste
3030
Delete the attachment from S3 when the note is removed /oc
3131
```
3232

33-
#### Review specific code lines
34-
35-
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.
36-
37-
```
38-
[Comment on specific lines in Files tab]
39-
/oc add error handling here
40-
```
41-
42-
When commenting on specific lines, opencode receives:
43-
44-
- The exact file being reviewed
45-
- The specific lines of code
46-
- The surrounding diff context
47-
- Line number information
48-
49-
This allows for more targeted requests without needing to specify file paths or line numbers manually.
50-
5133
## Installation
5234

5335
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
6951
on:
7052
issue_comment:
7153
types: [created]
72-
pull_request_review_comment:
73-
types: [created]
7454

7555
jobs:
7656
opencode:
@@ -155,9 +135,3 @@ Replace the image URL `https://github.com/user-attachments/assets/xxxxxxxx` with
155135
```
156136
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"}}}'
157137
```
158-
159-
### PR review comment event
160-
161-
```
162-
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"}}}'
163-
```

github/index.ts

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { graphql } from "@octokit/graphql"
55
import * as core from "@actions/core"
66
import * as github from "@actions/github"
77
import type { Context as GitHubContext } from "@actions/github/lib/context"
8-
import type { IssueCommentEvent, PullRequestReviewCommentEvent } from "@octokit/webhooks-types"
8+
import type { IssueCommentEvent } from "@octokit/webhooks-types"
99
import { createOpencodeClient } from "@opencode-ai/sdk"
1010
import { spawn } from "node:child_process"
1111

@@ -124,7 +124,7 @@ let exitCode = 0
124124
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
125125

126126
try {
127-
assertContextEvent("issue_comment", "pull_request_review_comment")
127+
assertContextEvent("issue_comment")
128128
assertPayloadKeyword()
129129
await assertOpencodeConnected()
130130

@@ -241,43 +241,19 @@ function createOpencode() {
241241
}
242242

243243
function assertPayloadKeyword() {
244-
const payload = useContext().payload as IssueCommentEvent | PullRequestReviewCommentEvent
244+
const payload = useContext().payload as IssueCommentEvent
245245
const body = payload.comment.body.trim()
246246
if (!body.match(/(?:^|\s)(?:\/opencode|\/oc)(?=$|\s)/)) {
247247
throw new Error("Comments must mention `/opencode` or `/oc`")
248248
}
249249
}
250250

251-
function getReviewCommentContext() {
252-
const context = useContext()
253-
if (context.eventName !== "pull_request_review_comment") {
254-
return null
255-
}
256-
257-
const payload = context.payload as PullRequestReviewCommentEvent
258-
return {
259-
file: payload.comment.path,
260-
diffHunk: payload.comment.diff_hunk,
261-
line: payload.comment.line,
262-
originalLine: payload.comment.original_line,
263-
position: payload.comment.position,
264-
commitId: payload.comment.commit_id,
265-
originalCommitId: payload.comment.original_commit_id,
266-
}
267-
}
268-
269251
async function assertOpencodeConnected() {
270252
let retry = 0
271253
let connected = false
272254
do {
273255
try {
274-
await client.app.log<true>({
275-
body: {
276-
service: "github-workflow",
277-
level: "info",
278-
message: "Prepare to react to Github Workflow event",
279-
},
280-
})
256+
await client.app.get<true>()
281257
connected = true
282258
break
283259
} catch (e) {}
@@ -407,24 +383,11 @@ async function createComment() {
407383
}
408384

409385
async function getUserPrompt() {
410-
const context = useContext()
411-
const payload = context.payload as IssueCommentEvent | PullRequestReviewCommentEvent
412-
const reviewContext = getReviewCommentContext()
413-
414386
let prompt = (() => {
387+
const payload = useContext().payload as IssueCommentEvent
415388
const body = payload.comment.body.trim()
416-
if (body === "/opencode" || body === "/oc") {
417-
if (reviewContext) {
418-
return `Review this code change and suggest improvements for the commented lines:\n\nFile: ${reviewContext.file}\nLines: ${reviewContext.line}\n\n${reviewContext.diffHunk}`
419-
}
420-
return "Summarize this thread"
421-
}
422-
if (body.includes("/opencode") || body.includes("/oc")) {
423-
if (reviewContext) {
424-
return `${body}\n\nContext: You are reviewing a comment on file "${reviewContext.file}" at line ${reviewContext.line}.\n\nDiff context:\n${reviewContext.diffHunk}`
425-
}
426-
return body
427-
}
389+
if (body === "/opencode" || body === "/oc") return "Summarize this thread"
390+
if (body.includes("/opencode") || body.includes("/oc")) return body
428391
throw new Error("Comments must mention `/opencode` or `/oc`")
429392
})()
430393

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

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { graphql } from "@octokit/graphql"
77
import * as core from "@actions/core"
88
import * as github from "@actions/github"
99
import type { Context } from "@actions/github/lib/context"
10-
import type { IssueCommentEvent, PullRequestReviewCommentEvent } from "@octokit/webhooks-types"
10+
import type { IssueCommentEvent } from "@octokit/webhooks-types"
1111
import { UI } from "../ui"
1212
import { cmd } from "./cmd"
1313
import { ModelsDev } from "../../provider/models"
@@ -328,8 +328,6 @@ export const GithubInstallCommand = cmd({
328328
on:
329329
issue_comment:
330330
types: [created]
331-
pull_request_review_comment:
332-
types: [created]
333331
334332
jobs:
335333
opencode:
@@ -380,7 +378,7 @@ export const GithubRunCommand = cmd({
380378
const isMock = args.token || args.event
381379

382380
const context = isMock ? (JSON.parse(args.event!) as Context) : github.context
383-
if (context.eventName !== "issue_comment" && context.eventName !== "pull_request_review_comment") {
381+
if (context.eventName !== "issue_comment") {
384382
core.setFailed(`Unsupported event type: ${context.eventName}`)
385383
process.exit(1)
386384
}
@@ -389,13 +387,9 @@ export const GithubRunCommand = cmd({
389387
const runId = normalizeRunId()
390388
const share = normalizeShare()
391389
const { owner, repo } = context.repo
392-
const payload = context.payload as IssueCommentEvent | PullRequestReviewCommentEvent
390+
const payload = context.payload as IssueCommentEvent
393391
const actor = context.actor
394-
395-
const issueId =
396-
context.eventName === "pull_request_review_comment"
397-
? (payload as PullRequestReviewCommentEvent).pull_request.number
398-
: (payload as IssueCommentEvent).issue.number
392+
const issueId = payload.issue.number
399393
const runUrl = `/${owner}/${repo}/actions/runs/${runId}`
400394
const shareBaseUrl = isMock ? "https://dev.opencode.ai" : "https://opencode.ai"
401395

@@ -537,39 +531,11 @@ export const GithubRunCommand = cmd({
537531
throw new Error(`Invalid share value: ${value}. Share must be a boolean.`)
538532
}
539533

540-
function getReviewCommentContext() {
541-
if (context.eventName !== "pull_request_review_comment") {
542-
return null
543-
}
544-
545-
const reviewPayload = payload as PullRequestReviewCommentEvent
546-
return {
547-
file: reviewPayload.comment.path,
548-
diffHunk: reviewPayload.comment.diff_hunk,
549-
line: reviewPayload.comment.line,
550-
originalLine: reviewPayload.comment.original_line,
551-
position: reviewPayload.comment.position,
552-
commitId: reviewPayload.comment.commit_id,
553-
originalCommitId: reviewPayload.comment.original_commit_id,
554-
}
555-
}
556-
557534
async function getUserPrompt() {
558-
const reviewContext = getReviewCommentContext()
559535
let prompt = (() => {
560536
const body = payload.comment.body.trim()
561-
if (body === "/opencode" || body === "/oc") {
562-
if (reviewContext) {
563-
return `Review this code change and suggest improvements for the commented lines:\n\nFile: ${reviewContext.file}\nLines: ${reviewContext.line}\n\n${reviewContext.diffHunk}`
564-
}
565-
return "Summarize this thread"
566-
}
567-
if (body.includes("/opencode") || body.includes("/oc")) {
568-
if (reviewContext) {
569-
return `${body}\n\nContext: You are reviewing a comment on file "${reviewContext.file}" at line ${reviewContext.line}.\n\nDiff context:\n${reviewContext.diffHunk}`
570-
}
571-
return body
572-
}
537+
if (body === "/opencode" || body === "/oc") return "Summarize this thread"
538+
if (body.includes("/opencode") || body.includes("/oc")) return body
573539
throw new Error("Comments must mention `/opencode` or `/oc`")
574540
})()
575541

packages/web/src/content/docs/github.mdx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ Or you can set it up manually.
4545
on:
4646
issue_comment:
4747
types: [created]
48-
pull_request_review_comment:
49-
types: [created]
5048

5149
jobs:
5250
opencode:
@@ -131,20 +129,3 @@ Here are some examples of how you can use opencode in GitHub.
131129
```
132130

133131
opencode will implement the requested change and commit it to the same PR.
134-
135-
- **Review specific code lines**
136-
137-
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.
138-
139-
```
140-
[Comment on specific lines in Files tab]
141-
/oc add error handling here
142-
```
143-
144-
When commenting on specific lines, opencode receives:
145-
- The exact file being reviewed
146-
- The specific lines of code
147-
- The surrounding diff context
148-
- Line number information
149-
150-
This allows for more targeted requests without needing to specify file paths or line numbers manually.

0 commit comments

Comments
 (0)