( storage: HttpStorageProvider, environment: HttpImportEnvironment, )
| 97 | } |
| 98 | |
| 99 | function createUniqueEnvironment( |
| 100 | storage: HttpStorageProvider, |
| 101 | environment: HttpImportEnvironment, |
| 102 | ): number { |
| 103 | const baseName = normalizeImportName(environment.name, 'Imported') |
| 104 | |
| 105 | for (let suffix = 0; suffix <= 10_000; suffix += 1) { |
| 106 | const candidate = withSuffix(baseName, suffix) |
| 107 | try { |
| 108 | const { id } = storage.environments.createEnvironment({ |
| 109 | name: candidate, |
| 110 | variables: environment.variables, |
| 111 | }) |
| 112 | return id |
| 113 | } |
| 114 | catch (error) { |
| 115 | if (parseStorageError(error)?.code !== 'NAME_CONFLICT') { |
| 116 | throw error |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | throw new Error('NAME_CONFLICT:Cannot generate unique environment name') |
| 122 | } |
| 123 | |
| 124 | function selectByIndexes<T>(items: T[], indexes: number[] | undefined): T[] { |
| 125 | if (!indexes) { |
no test coverage detected