( token: string, owner: string, repo: string, title: string, body: string, labels: string[] )
| 91 | error: "You don't have write (push) access to this repository.", |
| 92 | }; |
| 93 | } |
| 94 | } |
| 95 | return { canCreate: true }; |
| 96 | } |
| 97 | |
| 98 | // ── Issue API ── |
| 99 | |
| 100 | export async function createIssue( |
| 101 | token: string, |
| 102 | owner: string, |
| 103 | repo: string, |
| 104 | title: string, |
| 105 | body: string, |
| 106 | labels: string[] |
| 107 | ) { |
| 108 | const payload: Record<string, unknown> = { title, body }; |
| 109 | if (labels.length > 0) payload.labels = labels; |
| 110 | |
| 111 | const res = await ghFetch(`/repos/${owner}/${repo}/issues`, token, { |
| 112 | method: 'POST', |
| 113 | body: JSON.stringify(payload), |
| 114 | headers: { 'Content-Type': 'application/json' }, |
| 115 | }); |
| 116 | |
| 117 | if (!res.ok) { |
| 118 | const err = await res.json().catch(() => ({ message: res.statusText })); |
| 119 | if (res.status === 403) { |
| 120 | if (err.message?.includes('Resource not accessible')) |
| 121 | throw new Error(`PERMISSION_DENIED: ${err.message}`); |
| 122 | if (err.message?.includes('rate limit') || err.message?.includes('abuse')) |
| 123 | throw new Error(`RATE_LIMITED: ${err.message}`); |
| 124 | } |
| 125 | if (res.status === 401) { |
| 126 | throw new Error(`PERMISSION_DENIED: Token expired or invalid (401 Unauthorized)`); |
| 127 | } |
no test coverage detected