| 146 | * to allow `useProject` responses to still happen. |
| 147 | */ |
| 148 | export function useUnknownProject() { |
| 149 | const projects = new Map<string, Project>(); |
| 150 | client.scenario.get(`/:version/projects/:projectNameOrId`, (req, res) => { |
| 151 | const project = Array.from(projects.values()).find( |
| 152 | p => |
| 153 | p.id === req.params.projectNameOrId || |
| 154 | p.name === req.params.projectNameOrId |
| 155 | ); |
| 156 | if (project) { |
| 157 | return res.json(project); |
| 158 | } |
| 159 | res.status(404).send(); |
| 160 | }); |
| 161 | client.scenario.post(`/:version/projects`, (req, res) => { |
| 162 | const project = { |
| 163 | ...defaultProject, |
| 164 | ...req.body, |
| 165 | id: req.body.name, |
| 166 | }; |
| 167 | projects.set(project.id, project); |
| 168 | res.json(project); |
| 169 | }); |
| 170 | client.scenario.post(`/v9/projects/:projectNameOrId/link`, (req, res) => { |
| 171 | const { type, repo, org } = req.body; |
| 172 | const projName = req.params.projectNameOrId; |
| 173 | const project = Array.from(projects.values()).find( |
| 174 | p => p.name === projName || p.id === projName |
| 175 | ); |
| 176 | if (!project) { |
| 177 | return res.status(404).send('Invalid Project name or ID'); |
| 178 | } |
| 179 | if ( |
| 180 | (type === 'github' || type === 'gitlab' || type === 'bitbucket') && |
| 181 | (repo === 'user/repo' || repo === 'user2/repo2' || repo === 'user3/repo3') |
| 182 | ) { |
| 183 | project.link = { |
| 184 | type, |
| 185 | repo, |
| 186 | repoId: 1010, |
| 187 | org, |
| 188 | gitCredentialId: '', |
| 189 | sourceless: true, |
| 190 | createdAt: 1656109539791, |
| 191 | updatedAt: 1656109539791, |
| 192 | }; |
| 193 | res.json(project); |
| 194 | } else { |
| 195 | if (type === 'github') { |
| 196 | res.status(400).json({ |
| 197 | message: `To link a GitHub repository, you need to install the GitHub integration first. (400)\nInstall GitHub App: https://github.com/apps/vercel`, |
| 198 | action: 'Install GitHub App', |
| 199 | link: 'https://github.com/apps/vercel', |
| 200 | repo, |
| 201 | }); |
| 202 | } else { |
| 203 | res.status(400).json({ |
| 204 | code: 'repo_not_found', |
| 205 | message: `The repository "${repo}" couldn't be found in your linked ${formatProvider( |