@@ -10,7 +10,7 @@ import { parsePatch, applyPatches, ParsedDiff } from 'diff'
1010import path from 'path'
1111import vscode from 'vscode'
1212// import { ExportIntent } from '@amzn/codewhisperer-streaming'
13- import { TransformByQReviewStatus , transformByQState } from '../../models/model'
13+ import { TransformByQReviewStatus , transformByQState , PatchInfo } from '../../models/model'
1414import { ExportResultArchiveStructure } from '../../../shared/utilities/download'
1515import { getLogger } from '../../../shared/logger'
1616import { telemetry } from '../../../shared/telemetry/telemetry'
@@ -21,12 +21,6 @@ import * as CodeWhispererConstants from '../../models/constants'
2121import { ChatSessionManager } from '../../../amazonqGumby/chat/storages/chatSession'
2222import { setContext } from '../../../shared/vscode/setContext'
2323
24- type PatchDescription = {
25- name : string
26- fileName : string
27- isSuccessful : boolean
28- }
29-
3024export abstract class ProposedChangeNode {
3125 abstract readonly resourcePath : string
3226
@@ -160,7 +154,7 @@ export class DiffModel {
160154 * @param pathToWorkspace Path to the project that was transformed
161155 * @returns List of nodes containing the paths of files that were modified, added, or removed
162156 */
163- public parseDiff ( pathToDiff : string , pathToWorkspace : string , diffDescription : PatchDescription ) : PatchFileNode {
157+ public parseDiff ( pathToDiff : string , pathToWorkspace : string , diffDescription : PatchInfo ) : PatchFileNode {
164158 this . patchFileNodes = [ ]
165159 const diffContents = fs . readFileSync ( pathToDiff , 'utf8' )
166160 const changedFiles = parsePatch ( diffContents )
@@ -241,9 +235,6 @@ export class DiffModel {
241235
242236 public clearChanges ( ) {
243237 this . patchFileNodes = [ ]
244- // transformByQState.setSummaryFilePath('')
245- // transformByQState.setProjectCopyFilePath('')
246- // transformByQState.setResultArchiveFilePath('')
247238 }
248239}
249240
@@ -320,7 +311,7 @@ export class ProposedTransformationExplorer {
320311 getLogger ( ) . error ( err )
321312 } else {
322313 files . forEach ( ( file ) => {
323- const filePath = path . join ( path . join ( pathContainingArchive , 'patch' ) , file )
314+ const filePath = path . join ( pathContainingArchive , 'patch' , file )
324315 if ( file . endsWith ( '.patch' ) ) {
325316 patchFiles . push ( filePath )
326317 }
@@ -331,7 +322,7 @@ export class ProposedTransformationExplorer {
331322 const pathContainingPatchFileDescriptions = path . join ( pathContainingArchive , 'patch' , 'diff.json' )
332323
333324 const jsonData = fs . readFileSync ( pathContainingPatchFileDescriptions , 'utf-8' )
334- const patchFilesDescriptions : PatchDescription [ ] = JSON . parse ( jsonData )
325+ const patchFilesDescriptions : PatchInfo [ ] = JSON . parse ( jsonData )
335326
336327 const reset = async ( ) => {
337328 await setContext ( 'gumby.transformationProposalReviewInProgress' , false )
@@ -346,6 +337,7 @@ export class ProposedTransformationExplorer {
346337 }
347338
348339 diffModel . clearChanges ( )
340+ diffModel . currentPatchIndex = 0
349341 transformByQState . setSummaryFilePath ( '' )
350342 transformByQState . setProjectCopyFilePath ( '' )
351343 transformByQState . setResultArchiveFilePath ( '' )
@@ -439,7 +431,7 @@ export class ProposedTransformationExplorer {
439431 // const zip = new AdmZip(pathToArchive)
440432 // zip.extractAllTo(pathContainingArchive)
441433
442- getLogger ( ) . info ( 'descriptions' , patchFilesDescriptions . toString ( ) )
434+ //Because multiple patches are returned once the ZIP is downloaded, we want to show the first one to start
443435 diffModel . parseDiff ( patchFiles [ 0 ] , transformByQState . getProjectPath ( ) , patchFilesDescriptions [ 0 ] )
444436
445437 await setContext ( 'gumby.reviewState' , TransformByQReviewStatus . InReview )
@@ -474,7 +466,8 @@ export class ProposedTransformationExplorer {
474466 diffModel . saveChanges ( )
475467 telemetry . ui_click . emit ( { elementId : 'transformationHub_acceptChanges' } )
476468 void vscode . window . showInformationMessage ( CodeWhispererConstants . changesAppliedNotification )
477- if ( ! diffModel . currentPatchIndex ) {
469+ //We do this to ensure that the changesAppliedChatMessage is only sent to user when they accept the first diff.patch
470+ if ( diffModel . currentPatchIndex === 0 ) {
478471 transformByQState . getChatControllers ( ) ?. transformationFinished . fire ( {
479472 message : CodeWhispererConstants . changesAppliedChatMessage ,
480473 tabID : ChatSessionManager . Instance . getSession ( ) . tabID ,
@@ -506,7 +499,6 @@ export class ProposedTransformationExplorer {
506499
507500 vscode . commands . registerCommand ( 'aws.amazonq.transformationHub.reviewChanges.rejectChanges' , async ( ) => {
508501 diffModel . rejectChanges ( )
509- diffModel . currentPatchIndex = 0
510502 await reset ( )
511503 telemetry . ui_click . emit ( { elementId : 'transformationHub_rejectChanges' } )
512504
0 commit comments