github-triage.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { Octokit } from "@octokit/rest"
  2. import { tool } from "@opencode-ai/plugin"
  3. import DESCRIPTION from "./github-triage.txt"
  4. function getIssueNumber(): number {
  5. const issue = parseInt(process.env.ISSUE_NUMBER ?? "", 10)
  6. if (!issue) throw new Error("ISSUE_NUMBER env var not set")
  7. return issue
  8. }
  9. export default tool({
  10. description: DESCRIPTION,
  11. args: {
  12. assignee: tool.schema
  13. .enum(["thdxr", "adamdotdevin", "rekram1-node", "fwang", "jayair", "kommander"])
  14. .describe("The username of the assignee")
  15. .default("rekram1-node"),
  16. labels: tool.schema
  17. .array(tool.schema.enum(["nix", "opentui", "perf", "web", "zen", "docs"]))
  18. .describe("The labels(s) to add to the issue")
  19. .optional(),
  20. },
  21. async execute(args) {
  22. const issue = getIssueNumber()
  23. const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN })
  24. const owner = "sst"
  25. const repo = "opencode"
  26. const results: string[] = []
  27. await octokit.rest.issues.addAssignees({
  28. owner,
  29. repo,
  30. issue_number: issue,
  31. assignees: [args.assignee],
  32. })
  33. results.push(`Assigned @${args.assignee} to issue #${issue}`)
  34. if (args.labels && args.labels.length > 0) {
  35. await octokit.rest.issues.addLabels({
  36. owner,
  37. repo,
  38. issue_number: issue,
  39. labels: args.labels,
  40. })
  41. results.push(`Added labels: ${args.labels.join(", ")}`)
  42. }
  43. return results.join("\n")
  44. },
  45. })