( client: Client, projectLink: ProjectLink, path: string )
| 237 | } |
| 238 | |
| 239 | async function hasProjectLink( |
| 240 | client: Client, |
| 241 | projectLink: ProjectLink, |
| 242 | path: string |
| 243 | ): Promise<boolean> { |
| 244 | // "linked" via env vars? |
| 245 | const VERCEL_ORG_ID = getPlatformEnv('ORG_ID'); |
| 246 | const VERCEL_PROJECT_ID = getPlatformEnv('PROJECT_ID'); |
| 247 | if ( |
| 248 | VERCEL_ORG_ID === projectLink.orgId && |
| 249 | VERCEL_PROJECT_ID === projectLink.projectId |
| 250 | ) { |
| 251 | return true; |
| 252 | } |
| 253 | |
| 254 | // linked via `repo.json`? |
| 255 | const repoLink = await getRepoLink(client, path); |
| 256 | if (repoLink?.repoConfig) { |
| 257 | const matchingProject = repoLink.repoConfig.projects.find( |
| 258 | p => p.id === projectLink.projectId |
| 259 | ); |
| 260 | if (matchingProject) { |
| 261 | // Prefer project-level orgId, fall back to top-level for backwards compat |
| 262 | const orgId = matchingProject.orgId ?? repoLink.repoConfig.orgId; |
| 263 | if (!orgId) { |
| 264 | throw new Error( |
| 265 | `Invalid "repo.json": missing "orgId" for project "${matchingProject.id}" and no top-level "orgId" is defined.` |
| 266 | ); |
| 267 | } |
| 268 | if (orgId === projectLink.orgId) { |
| 269 | return true; |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | // if the project is already linked, we skip linking |
| 275 | const link = await getLinkFromDir(getVercelDirectory(path)); |
| 276 | if ( |
| 277 | link && |
| 278 | link.orgId === projectLink.orgId && |
| 279 | link.projectId === projectLink.projectId |
| 280 | ) { |
| 281 | return true; |
| 282 | } |
| 283 | |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | export async function getLinkedProject( |
| 288 | client: Client, |
no test coverage detected