(owner: string, repo: string)
| 204 | * under an organization (`POST /orgs/{org}/repos`). |
| 205 | */ |
| 206 | export async function gitcodeCreateRepo(owner: string, repo: string): Promise<void> { |
| 207 | const token = requireToken(); |
| 208 | const login = await gitcodeWhoami(); |
| 209 | |
| 210 | const isOrg = !login || login.toLowerCase() !== owner.toLowerCase(); |
| 211 | const endpoint = isOrg |
| 212 | ? `${gitcodeApiBase()}/orgs/${encodeURIComponent(owner)}/repos` |
| 213 | : `${gitcodeApiBase()}/user/repos`; |
| 214 | |
| 215 | const body: Record<string, unknown> = { name: repo, private: true, auto_init: true }; |
| 216 | |
| 217 | const resp = await fetch(endpoint, { |
| 218 | method: 'POST', |
| 219 | headers: authHeaders(token), |
| 220 | body: JSON.stringify(body), |
| 221 | redirect: 'manual', |
| 222 | }); |
| 223 | if (!resp.ok) { |
| 224 | const errBody = await resp.text().catch(() => ''); |
| 225 | throw new Error(`Failed to create GitCode repo: ${resp.status} ${errBody}`); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // ─── Pull requests ─────────────────────────────────────── |
| 230 |
no test coverage detected