Skip to content

Commit 80235f3

Browse files
committed
ci: fix dup pr action
1 parent 88c306e commit 80235f3

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

.github/workflows/duplicate-prs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030
- name: Setup Bun
3131
uses: ./.github/actions/setup-bun
3232

33-
- name: Install opencode
34-
run: curl -fsSL https://opencode.ai/install | bash
33+
- name: Install dependencies
34+
run: bun install
3535

3636
- name: Build prompt
3737
env:
@@ -53,7 +53,7 @@ jobs:
5353
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5454
PR_NUMBER: ${{ github.event.pull_request.number }}
5555
run: |
56-
COMMENT=$(opencode run --agent duplicate-pr --print -f pr_info.txt "Check the attached file for PR details and search for duplicates")
56+
COMMENT=$(bun script/duplicate-pr.ts -f pr_info.txt "Check the attached file for PR details and search for duplicates")
5757
5858
gh pr comment "$PR_NUMBER" --body "_The following comment was made by an LLM, it may be inaccurate:_
5959

script/duplicate-pr.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bun
2+
3+
import path from "path"
4+
import { createOpencode } from "@opencode-ai/sdk"
5+
import { parseArgs } from "util"
6+
7+
async function main() {
8+
const { values, positionals } = parseArgs({
9+
args: Bun.argv.slice(2),
10+
options: {
11+
file: { type: "string", short: "f" },
12+
help: { type: "boolean", short: "h", default: false },
13+
},
14+
allowPositionals: true,
15+
})
16+
17+
if (values.help) {
18+
console.log(`
19+
Usage: bun script/duplicate-pr.ts [options] <message>
20+
21+
Options:
22+
-f, --file <path> File to attach to the prompt
23+
-h, --help Show this help message
24+
25+
Examples:
26+
bun script/duplicate-pr.ts -f pr_info.txt "Check the attached file for PR details"
27+
`)
28+
process.exit(0)
29+
}
30+
31+
const message = positionals.join(" ")
32+
if (!message) {
33+
console.error("Error: message is required")
34+
process.exit(1)
35+
}
36+
37+
const opencode = await createOpencode({ port: 0 })
38+
39+
try {
40+
const parts: Array<{ type: "text"; text: string } | { type: "file"; url: string; filename: string; mime: string }> =
41+
[]
42+
43+
if (values.file) {
44+
const resolved = path.resolve(process.cwd(), values.file)
45+
const file = Bun.file(resolved)
46+
if (!(await file.exists())) {
47+
console.error(`Error: file not found: ${values.file}`)
48+
process.exit(1)
49+
}
50+
parts.push({
51+
type: "file",
52+
url: `file://${resolved}`,
53+
filename: path.basename(resolved),
54+
mime: "text/plain",
55+
})
56+
}
57+
58+
parts.push({ type: "text", text: message })
59+
60+
const session = await opencode.client.session.create()
61+
const result = await opencode.client.session
62+
.prompt({
63+
path: { id: session.data!.id },
64+
body: {
65+
agent: "duplicate-pr",
66+
parts,
67+
},
68+
signal: AbortSignal.timeout(120_000),
69+
})
70+
.then((x) => x.data?.parts?.find((y) => y.type === "text")?.text ?? "")
71+
72+
console.log(result.trim())
73+
} finally {
74+
opencode.server.close()
75+
}
76+
}
77+
78+
main()

0 commit comments

Comments
 (0)