(endpoint: string, token: string, method: string = 'GET', body?: any)
| 26 | } |
| 27 | |
| 28 | async function githubRequest<T>(endpoint: string, token: string, method: string = 'GET', body?: any): Promise<T> { |
| 29 | const response = await fetch(`https://api.github.com${endpoint}`, { |
| 30 | method, |
| 31 | headers: { |
| 32 | Authorization: `Bearer ${token}`, |
| 33 | Accept: "application/vnd.github.v3+json", |
| 34 | "User-Agent": "auto-close-duplicates-script", |
| 35 | ...(body && { "Content-Type": "application/json" }), |
| 36 | }, |
| 37 | ...(body && { body: JSON.stringify(body) }), |
| 38 | }); |
| 39 | |
| 40 | if (!response.ok) { |
| 41 | throw new Error( |
| 42 | `GitHub API request failed: ${response.status} ${response.statusText}` |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | return response.json(); |
| 47 | } |
| 48 | |
| 49 | function extractDuplicateIssueNumber(commentBody: string): number | null { |
| 50 | // Try to match #123 format first |
no outgoing calls
no test coverage detected