@@ -79,7 +79,6 @@ import { convertDateToTimestamp } from '../../shared/datetime'
7979import { findStringInDirectory } from '../../shared/utilities/workspaceUtils'
8080import { makeTemporaryToolkitFolder } from '../../shared/filesystemUtilities'
8181import { AuthUtil } from '../util/authUtil'
82- import { homedir } from 'os'
8382
8483export function getFeedbackCommentData ( ) {
8584 const jobId = transformByQState . getJobId ( )
@@ -476,6 +475,30 @@ export async function startTransformationJob(
476475 codeTransformRunTimeLatency : calculateTotalLatency ( transformStartTime ) ,
477476 } )
478477 } )
478+
479+ // create local history folder(s) and store metadata
480+ const jobHistoryPath = path . join ( os . homedir ( ) , '.aws' , 'transform' , transformByQState . getProjectName ( ) , jobId )
481+ if ( ! fs . existsSync ( jobHistoryPath ) ) {
482+ fs . mkdirSync ( jobHistoryPath , { recursive : true } )
483+ }
484+ transformByQState . setJobHistoryPath ( jobHistoryPath )
485+ // save a copy of the upload zip
486+ fs . copyFileSync ( transformByQState . getPayloadFilePath ( ) , path . join ( jobHistoryPath , 'zipped-code.zip' ) )
487+
488+ const fields = [
489+ jobId ,
490+ transformByQState . getTransformationType ( ) ,
491+ transformByQState . getSourceJDKVersion ( ) ,
492+ transformByQState . getTargetJDKVersion ( ) ,
493+ transformByQState . getCustomDependencyVersionFilePath ( ) ,
494+ transformByQState . getCustomBuildCommand ( ) ,
495+ transformByQState . getTargetJavaHome ( ) ,
496+ transformByQState . getProjectPath ( ) ,
497+ transformByQState . getStartTime ( ) ,
498+ ]
499+
500+ const jobDetails = fields . join ( '\t' )
501+ fs . writeFileSync ( path . join ( jobHistoryPath , 'metadata.txt' ) , jobDetails )
479502 } catch ( error ) {
480503 getLogger ( ) . error ( `CodeTransformation: ${ CodeWhispererConstants . failedToStartJobNotification } ` , error )
481504 const errorMessage = ( error as Error ) . message . toLowerCase ( )
@@ -726,9 +749,19 @@ export async function postTransformationJob() {
726749 } )
727750 }
728751
729- if ( transformByQState . getPayloadFilePath ( ) ) {
730- // delete original upload ZIP at very end of transformation
731- fs . rmSync ( transformByQState . getPayloadFilePath ( ) , { force : true } )
752+ if (
753+ transformByQState . isSucceeded ( ) ||
754+ transformByQState . isPartiallySucceeded ( ) ||
755+ transformByQState . isCancelled ( )
756+ ) {
757+ if ( transformByQState . getPayloadFilePath ( ) ) {
758+ // delete original upload ZIP at very end of transformation
759+ fs . rmSync ( transformByQState . getPayloadFilePath ( ) , { force : true } )
760+ // delete the copy of the upload ZIP
761+ fs . rmSync ( path . join ( transformByQState . getJobHistoryPath ( ) , 'zipped-code.zip' ) , { force : true } )
762+ }
763+ // delete transformation job metadata file (no longer needed)
764+ fs . rmSync ( path . join ( transformByQState . getJobHistoryPath ( ) , 'metadata.txt' ) , { force : true } )
732765 }
733766 // delete temporary build logs file
734767 const logFilePath = path . join ( os . tmpdir ( ) , 'build-logs.txt' )
@@ -745,28 +778,30 @@ export async function postTransformationJob() {
745778 // store job details and diff path locally (history)
746779 // TODO: ideally when job is cancelled, should be stored as CANCELLED instead of FAILED (remove this if statement after bug is fixed)
747780 if ( ! transformByQState . isCancelled ( ) ) {
748- const jobHistoryFilePath = path . join ( homedir ( ) , '.aws' , 'transform' , 'transformation-history.tsv' )
781+ const historyLogFilePath = path . join ( os . homedir ( ) , '.aws' , 'transform' , 'transformation-history.tsv' )
749782 // create transform folder if necessary
750- if ( ! fs . existsSync ( jobHistoryFilePath ) ) {
751- fs . mkdirSync ( path . dirname ( jobHistoryFilePath ) , { recursive : true } )
783+ if ( ! fs . existsSync ( historyLogFilePath ) ) {
784+ fs . mkdirSync ( path . dirname ( historyLogFilePath ) , { recursive : true } )
752785 // create headers of new transformation history file
753- fs . writeFileSync ( jobHistoryFilePath , 'date\tproject_name\tstatus\tduration\tdiff_path \tjob_id\n' )
786+ fs . writeFileSync ( historyLogFilePath , 'date\tproject_name\tstatus\tduration\tdiff_patch\tsummary \tjob_id\n' )
754787 }
755788 const latest = sessionJobHistory [ transformByQState . getJobId ( ) ]
756- const jobDetails : string =
757- latest . startTime +
758- '\t' +
759- latest . projectName +
760- '\t' +
761- latest . status +
762- '\t' +
763- latest . duration +
764- '\t' +
765- transformByQState . getDiffPatchFilePath ( ) +
766- '\t' +
767- transformByQState . getJobId ( ) +
768- '\n'
769- fs . writeFileSync ( jobHistoryFilePath , jobDetails , { flag : 'a' } )
789+ const fields = [
790+ latest . startTime ,
791+ latest . projectName ,
792+ latest . status ,
793+ latest . duration ,
794+ transformByQState . isSucceeded ( ) || transformByQState . isPartiallySucceeded ( )
795+ ? path . join ( transformByQState . getJobHistoryPath ( ) , 'diff.patch' )
796+ : '' ,
797+ transformByQState . isSucceeded ( ) || transformByQState . isPartiallySucceeded ( )
798+ ? path . join ( transformByQState . getJobHistoryPath ( ) , 'summary' , 'summary.md' )
799+ : '' ,
800+ transformByQState . getJobId ( ) ,
801+ ]
802+
803+ const jobDetails = fields . join ( '\t' ) + '\n'
804+ fs . writeFileSync ( historyLogFilePath , jobDetails , { flag : 'a' } )
770805 }
771806}
772807
0 commit comments