|
1 | 1 | /// <reference path="../env.d.ts" /> |
2 | | -import { Octokit } from "@octokit/rest" |
| 2 | +// import { Octokit } from "@octokit/rest" |
3 | 3 | import { tool } from "@opencode-ai/plugin" |
4 | 4 | import DESCRIPTION from "./github-triage.txt" |
5 | 5 |
|
@@ -9,6 +9,22 @@ function getIssueNumber(): number { |
9 | 9 | return issue |
10 | 10 | } |
11 | 11 |
|
| 12 | +async function githubFetch(endpoint: string, options: RequestInit = {}) { |
| 13 | + const response = await fetch(`https://api.github.com${endpoint}`, { |
| 14 | + ...options, |
| 15 | + headers: { |
| 16 | + Authorization: `Bearer ${process.env.GITHUB_TOKEN}`, |
| 17 | + Accept: "application/vnd.github+json", |
| 18 | + "Content-Type": "application/json", |
| 19 | + ...options.headers, |
| 20 | + }, |
| 21 | + }) |
| 22 | + if (!response.ok) { |
| 23 | + throw new Error(`GitHub API error: ${response.status} ${response.statusText}`) |
| 24 | + } |
| 25 | + return response.json() |
| 26 | +} |
| 27 | + |
12 | 28 | export default tool({ |
13 | 29 | description: DESCRIPTION, |
14 | 30 | args: { |
@@ -23,7 +39,7 @@ export default tool({ |
23 | 39 | }, |
24 | 40 | async execute(args) { |
25 | 41 | const issue = getIssueNumber() |
26 | | - const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }) |
| 42 | + // const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }) |
27 | 43 | const owner = "sst" |
28 | 44 | const repo = "opencode" |
29 | 45 |
|
@@ -41,22 +57,30 @@ export default tool({ |
41 | 57 | throw new Error("Only opentui issues should be assigned to kommander") |
42 | 58 | } |
43 | 59 |
|
44 | | - await octokit.rest.issues.addAssignees({ |
45 | | - owner, |
46 | | - repo, |
47 | | - issue_number: issue, |
48 | | - assignees: [args.assignee], |
| 60 | + // await octokit.rest.issues.addAssignees({ |
| 61 | + // owner, |
| 62 | + // repo, |
| 63 | + // issue_number: issue, |
| 64 | + // assignees: [args.assignee], |
| 65 | + // }) |
| 66 | + await githubFetch(`/repos/${owner}/${repo}/issues/${issue}/assignees`, { |
| 67 | + method: "POST", |
| 68 | + body: JSON.stringify({ assignees: [args.assignee] }), |
49 | 69 | }) |
50 | 70 | results.push(`Assigned @${args.assignee} to issue #${issue}`) |
51 | 71 |
|
52 | 72 | const labels: string[] = args.labels.map((label) => (label === "desktop" ? "web" : label)) |
53 | 73 |
|
54 | 74 | if (labels.length > 0) { |
55 | | - await octokit.rest.issues.addLabels({ |
56 | | - owner, |
57 | | - repo, |
58 | | - issue_number: issue, |
59 | | - labels, |
| 75 | + // await octokit.rest.issues.addLabels({ |
| 76 | + // owner, |
| 77 | + // repo, |
| 78 | + // issue_number: issue, |
| 79 | + // labels, |
| 80 | + // }) |
| 81 | + await githubFetch(`/repos/${owner}/${repo}/issues/${issue}/labels`, { |
| 82 | + method: "POST", |
| 83 | + body: JSON.stringify({ labels }), |
60 | 84 | }) |
61 | 85 | results.push(`Added labels: ${args.labels.join(", ")}`) |
62 | 86 | } |
|