( token: string, owner: string, repo: string )
| 67 | } |
| 68 | |
| 69 | export async function testRepoPermission( |
| 70 | token: string, |
| 71 | owner: string, |
| 72 | repo: string |
| 73 | ): Promise<{ canCreate: boolean; error?: string }> { |
| 74 | const repoRes = await ghFetch(`/repos/${owner}/${repo}`, token); |
| 75 | if (!repoRes.ok) { |
| 76 | const err = await repoRes.json().catch(() => ({ message: repoRes.statusText })); |
| 77 | return { canCreate: false, error: `Cannot access repo: ${err.message}` }; |
| 78 | } |
| 79 | const repoData = await repoRes.json(); |
| 80 | if (repoData.permissions) { |
| 81 | if (!repoData.permissions.push && !repoData.permissions.admin) { |
| 82 | return { |
| 83 | canCreate: false, |
| 84 | error: "You don't have write (push) access to this repository.", |
| 85 | }; |
| 86 | } |
| 87 | } |
| 88 | return { canCreate: true }; |
| 89 | } |
| 90 | |
| 91 | // ── Issue API ── |
| 92 |
no test coverage detected