Skip to content

Commit 9f4563b

Browse files
committed
refactor: consolidate generateZip
1 parent 8f4521a commit 9f4563b

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

packages/core/src/codewhisperer/util/zipUtil.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,7 @@ export class ZipUtil {
346346
if (!options?.silent) {
347347
getLogger().debug(`Picked source files: [${[...this._pickedSourceFiles].join(', ')}]`)
348348
}
349-
return {
350-
rootDir: zipDirPath,
351-
zipFilePath: zipFilePath,
352-
srcPayloadSizeInBytes: this._totalSize,
353-
scannedFiles: new Set([...this._pickedSourceFiles, ...this._pickedBuildFiles]),
354-
zipFileSizeInBytes: (await fs.stat(zipFilePath)).size,
355-
buildPayloadSizeInBytes: this._totalBuildSize,
356-
lines: this._totalLines,
357-
language: this._language,
358-
}
349+
return this.getGenerateZipResult(zipDirPath, zipFilePath)
359350
} catch (error) {
360351
getLogger().error('Zip error caused by: %O', error)
361352
throw error
@@ -376,16 +367,7 @@ export class ZipUtil {
376367
if (!options?.silent) {
377368
getLogger().debug(`Picked source files: [${[...this._pickedSourceFiles].join(', ')}]`)
378369
}
379-
return {
380-
rootDir: zipDirPath,
381-
zipFilePath: zipFilePath,
382-
srcPayloadSizeInBytes: this._totalSize,
383-
scannedFiles: new Set([...this._pickedSourceFiles, ...this._pickedBuildFiles]),
384-
zipFileSizeInBytes: (await fs.stat(zipFilePath)).size,
385-
buildPayloadSizeInBytes: this._totalBuildSize,
386-
lines: this._totalLines,
387-
language: this._language,
388-
}
370+
return this.getGenerateZipResult(zipDirPath, zipFilePath)
389371
} catch (error) {
390372
getLogger().error('Zip error caused by: %O', error)
391373
throw error
@@ -429,23 +411,27 @@ export class ZipUtil {
429411
}
430412
)
431413

432-
return {
433-
rootDir: zipDirPath,
434-
zipFilePath: zipFilePath,
435-
srcPayloadSizeInBytes: this._totalSize,
436-
scannedFiles: new Set(this._pickedSourceFiles),
437-
zipFileSizeInBytes: (await fs.stat(zipFilePath)).size,
438-
buildPayloadSizeInBytes: this._totalBuildSize,
439-
lines: this._totalLines,
440-
language: this._language,
441-
}
414+
return this.getGenerateZipResult(zipDirPath, zipFilePath)
442415
} catch (error) {
443416
getLogger().error('Zip error caused by: %s', error)
444417
throw new ProjectZipError(
445418
error instanceof Error ? error.message : 'Unknown error occurred during zip operation'
446419
)
447420
}
448421
}
422+
423+
protected async getGenerateZipResult(zipDirpath: string, zipFilePath: string): Promise<ZipMetadata> {
424+
return {
425+
rootDir: zipDirpath,
426+
zipFilePath: zipFilePath,
427+
srcPayloadSizeInBytes: this._totalSize,
428+
scannedFiles: new Set(this._pickedSourceFiles),
429+
zipFileSizeInBytes: (await fs.stat(zipFilePath)).size,
430+
buildPayloadSizeInBytes: this._totalBuildSize,
431+
lines: this._totalLines,
432+
language: this._language,
433+
}
434+
}
449435
// TODO: Refactor this
450436
public async removeTmpFiles(zipMetadata: ZipMetadata, silent?: boolean) {
451437
const logger = silent ? getNullLogger() : getLogger()

0 commit comments

Comments
 (0)