github-triage.ts 2.0 KB

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