summaryrefslogtreecommitdiffhomepage
path: root/.opencode/tool
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2026-01-04 00:15:46 -0600
committerAiden Cline <[email protected]>2026-01-04 00:15:59 -0600
commitb934c22d8de2ddcf583a653c37d30a74532527af (patch)
tree22205c01b6d6143d6885f7e7e2ffdcace6e071a6 /.opencode/tool
parent72cef0d9e78ac771cd9044a3fe9f5a3d6f3db8b8 (diff)
downloadopencode-b934c22d8de2ddcf583a653c37d30a74532527af.tar.gz
opencode-b934c22d8de2ddcf583a653c37d30a74532527af.zip
ci: add duplicate PR detection bot
Diffstat (limited to '.opencode/tool')
-rw-r--r--.opencode/tool/github-pr-search.ts52
-rw-r--r--.opencode/tool/github-pr-search.txt10
2 files changed, 62 insertions, 0 deletions
diff --git a/.opencode/tool/github-pr-search.ts b/.opencode/tool/github-pr-search.ts
new file mode 100644
index 000000000..1c2a457a4
--- /dev/null
+++ b/.opencode/tool/github-pr-search.ts
@@ -0,0 +1,52 @@
+/// <reference path="../env.d.ts" />
+import { tool } from "@opencode-ai/plugin"
+import DESCRIPTION from "./github-pr-search.txt"
+
+async function githubFetch(endpoint: string, options: RequestInit = {}) {
+ const response = await fetch(`https://api.github.com${endpoint}`, {
+ ...options,
+ headers: {
+ Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
+ Accept: "application/vnd.github+json",
+ "Content-Type": "application/json",
+ ...options.headers,
+ },
+ })
+ if (!response.ok) {
+ throw new Error(`GitHub API error: ${response.status} ${response.statusText}`)
+ }
+ return response.json()
+}
+
+interface PR {
+ title: string
+ html_url: string
+}
+
+export default tool({
+ description: DESCRIPTION,
+ args: {
+ query: tool.schema.string().describe("Search query for PR titles and descriptions"),
+ limit: tool.schema.number().describe("Maximum number of results to return").default(10),
+ offset: tool.schema.number().describe("Number of results to skip for pagination").default(0),
+ },
+ async execute(args) {
+ const owner = "sst"
+ const repo = "opencode"
+
+ const page = Math.floor(args.offset / args.limit) + 1
+ const searchQuery = encodeURIComponent(`${args.query} repo:${owner}/${repo} type:pr state:open`)
+ const result = await githubFetch(
+ `/search/issues?q=${searchQuery}&per_page=${args.limit}&page=${page}&sort=updated&order=desc`,
+ )
+
+ if (result.total_count === 0) {
+ return `No PRs found matching "${args.query}"`
+ }
+
+ const prs = result.items as PR[]
+ const formatted = prs.map((pr) => `${pr.title}\n${pr.html_url}`).join("\n\n")
+
+ return `Found ${result.total_count} PRs (showing ${prs.length}):\n\n${formatted}`
+ },
+})
diff --git a/.opencode/tool/github-pr-search.txt b/.opencode/tool/github-pr-search.txt
new file mode 100644
index 000000000..28d8643f1
--- /dev/null
+++ b/.opencode/tool/github-pr-search.txt
@@ -0,0 +1,10 @@
+Use this tool to search GitHub pull requests by title and description.
+
+This tool searches PRs in the sst/opencode repository and returns LLM-friendly results including:
+- PR number and title
+- Author
+- State (open/closed/merged)
+- Labels
+- Description snippet
+
+Use the query parameter to search for keywords that might appear in PR titles or descriptions.