(options: CreateRepoOptions)
| 95 | } |
| 96 | |
| 97 | export async function createRepository(options: CreateRepoOptions) { |
| 98 | const token = await getPlainServiceToken('github'); |
| 99 | if (!token) { |
| 100 | throw new GitHubError('GitHub token not configured', 401); |
| 101 | } |
| 102 | |
| 103 | const payload = { |
| 104 | name: options.repoName, |
| 105 | description: options.description ?? '', |
| 106 | private: options.private ?? false, |
| 107 | auto_init: false, |
| 108 | }; |
| 109 | |
| 110 | try { |
| 111 | const repo = await githubFetch(token, '/user/repos', { |
| 112 | method: 'POST', |
| 113 | body: JSON.stringify(payload), |
| 114 | }); |
| 115 | |
| 116 | return repo as any; |
| 117 | } catch (error) { |
| 118 | if (error instanceof GitHubError && error.status === 422) { |
| 119 | throw new GitHubError(`Repository name "${options.repoName}" is unavailable or already exists.`, error.status); |
| 120 | } |
| 121 | throw error; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | function resolveProjectRepoPath(projectId: string, repoPath?: string | null) { |
| 126 | if (repoPath) { |
no test coverage detected