( repo: string, issueNumber: number, )
| 283 | |
| 284 | /** Fetch one issue. Uses GITHUB_TOKEN when set (private repos / rate limits). */ |
| 285 | export async function fetchIssue( |
| 286 | repo: string, |
| 287 | issueNumber: number, |
| 288 | ): Promise<GitHubIssue> { |
| 289 | const headers: Record<string, string> = { |
| 290 | Accept: 'application/vnd.github+json', |
| 291 | 'User-Agent': 'tanstack-ai-sandbox-triage', |
| 292 | } |
| 293 | if (process.env.GITHUB_TOKEN) { |
| 294 | headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}` |
| 295 | } |
| 296 | const res = await fetch( |
| 297 | `https://api.github.com/repos/${repo}/issues/${issueNumber}`, |
| 298 | { headers }, |
| 299 | ) |
| 300 | if (!res.ok) { |
| 301 | throw new Error( |
| 302 | `GitHub API ${res.status} ${res.statusText}: ${await res.text()}`, |
| 303 | ) |
| 304 | } |
| 305 | const issue = (await res.json()) as { |
| 306 | number: number |
| 307 | title: string |
| 308 | body: string | null |
| 309 | html_url: string |
| 310 | pull_request?: unknown |
| 311 | } |
| 312 | if (issue.pull_request !== undefined) { |
| 313 | throw new Error(`${repo}#${issueNumber} is a pull request, not an issue.`) |
| 314 | } |
| 315 | return { |
| 316 | number: issue.number, |
| 317 | title: issue.title, |
| 318 | body: issue.body ?? '', |
| 319 | url: issue.html_url, |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | export function buildTriagePrompt(issue: GitHubIssue, repo: string): string { |
| 324 | return [ |
no test coverage detected