(cloudProviderType: CloudProvider['type'], deploymentId: string, versionId?: string)
| 587 | } |
| 588 | |
| 589 | async function fetchDeployment(cloudProviderType: CloudProvider['type'], deploymentId: string, versionId?: string) { |
| 590 | // We need to call `fetchDeployments` even if we want just one deployment due to the way the deployment ID is build |
| 591 | // For that reason we keep the `deploymentId` paramater in `fetchDeployments` that allows to return early if the deployment is found |
| 592 | const goDeployemnts = await go(() => fetchDeployments(cloudProviderType, deploymentId)); |
| 593 | |
| 594 | if (!goDeployemnts.success) { |
| 595 | throw new Error( |
| 596 | `Failed to fetch info about '${deploymentId}' from ${cloudProviderType.toUpperCase()}: ${goDeployemnts.error}` |
| 597 | ); |
| 598 | } |
| 599 | |
| 600 | if (goDeployemnts.data.length === 0) { |
| 601 | throw new Error(`No deployment with ID '${deploymentId}' found`); |
| 602 | } |
| 603 | |
| 604 | const deployment = goDeployemnts.data[0]; |
| 605 | let requestedVersion: DeploymentVersion | undefined; |
| 606 | |
| 607 | if (versionId) { |
| 608 | requestedVersion = deployment.versions.find((version) => version.id === versionId); |
| 609 | if (!requestedVersion) { |
| 610 | throw new Error(`No deployment with ID '${deploymentId}' and version '${versionId}' found`); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | const version = requestedVersion ?? sortBy(deployment.versions, 'timestamp').reverse()[0]; |
| 615 | return { deployment, version }; |
| 616 | } |
| 617 | |
| 618 | async function downloadDeploymentFiles( |
| 619 | cloudProviderType: CloudProvider['type'], |
no test coverage detected