Skip to content

Commit 3ad9e0d

Browse files
committed
updated json structure based on backend and now collecting patchfiles from json
1 parent 9eee782 commit 3ad9e0d

File tree

8 files changed

+62
-40
lines changed

8 files changed

+62
-40
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
[
2-
{
3-
"name": "Added file",
4-
"fileName": "resources/files/addedFile.diff",
5-
"isSuccessful": true
6-
}
7-
]
1+
{
2+
"content": [
3+
{
4+
"name": "Added file",
5+
"fileName": "resources/files/addedFile.diff",
6+
"isSuccessful": true
7+
}
8+
]
9+
}

packages/amazonq/test/unit/amazonqGumby/transformationResultsHandler.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import assert from 'assert'
66
import sinon from 'sinon'
77
import os from 'os'
88
import { DiffModel, AddedChangeNode, ModifiedChangeNode } from 'aws-core-vscode/codewhisperer/node'
9-
import { PatchInfo } from 'aws-core-vscode/codewhisperer'
9+
import { DescriptionContent } from 'aws-core-vscode/codewhisperer'
1010
import path from 'path'
1111
import { getTestResourceFilePath } from './amazonQGumbyUtil'
1212
import { fs } from 'aws-core-vscode/shared'
1313

1414
describe('DiffModel', function () {
15-
let parsedTestDescriptions: PatchInfo[]
15+
let parsedTestDescriptions: DescriptionContent
1616
beforeEach(() => {
1717
const fs = require('fs')
1818
parsedTestDescriptions = JSON.parse(
@@ -40,14 +40,17 @@ describe('DiffModel', function () {
4040
testDiffModel.parseDiff(
4141
getTestResourceFilePath('resources/files/addedFile.diff'),
4242
workspacePath,
43-
parsedTestDescriptions[0],
43+
parsedTestDescriptions.content[0],
4444
1
4545
)
4646

4747
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
4848
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
49-
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescriptions[0].name)
50-
assert(testDiffModel.patchFileNodes[0].label.endsWith(parsedTestDescriptions[0].name))
49+
assert.strictEqual(
50+
testDiffModel.patchFileNodes[0].patchFilePath,
51+
getTestResourceFilePath('resources/files/addedFile.diff')
52+
)
53+
assert(testDiffModel.patchFileNodes[0].label.endsWith(parsedTestDescriptions.content[0].name))
5154
const change = testDiffModel.patchFileNodes[0].children[0]
5255

5356
assert.strictEqual(change instanceof AddedChangeNode, true)
@@ -68,14 +71,17 @@ describe('DiffModel', function () {
6871
testDiffModel.parseDiff(
6972
getTestResourceFilePath('resources/files/modifiedFile.diff'),
7073
workspacePath,
71-
parsedTestDescriptions[0],
74+
parsedTestDescriptions.content[0],
7275
1
7376
)
7477

7578
assert.strictEqual(testDiffModel.patchFileNodes.length, 1)
7679
assert.strictEqual(testDiffModel.patchFileNodes[0].children.length, 1)
77-
assert.strictEqual(testDiffModel.patchFileNodes[0].patchFilePath, parsedTestDescriptions[0].name)
78-
assert(testDiffModel.patchFileNodes[0].label.endsWith(parsedTestDescriptions[0].name))
80+
assert.strictEqual(
81+
testDiffModel.patchFileNodes[0].patchFilePath,
82+
getTestResourceFilePath('resources/files/modifiedFile.diff')
83+
)
84+
assert(testDiffModel.patchFileNodes[0].label.endsWith(parsedTestDescriptions.content[0].name))
7985
const change = testDiffModel.patchFileNodes[0].children[0]
8086

8187
assert.strictEqual(change instanceof ModifiedChangeNode, true)

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ export class GumbyController {
579579
private transformationFinished(data: {
580580
message: string | undefined
581581
tabID: string
582-
includeStartNewTransformationButton: string
582+
includeStartNewTransformationButton: boolean
583583
}) {
584584
this.resetTransformationChatFlow()
585585
// at this point job is either completed, partially_completed, cancelled, or failed
@@ -685,7 +685,7 @@ export class GumbyController {
685685
this.transformationFinished({
686686
tabID: message.tabID,
687687
message: (err as Error).message,
688-
includeStartNewTransformationButton: 'true',
688+
includeStartNewTransformationButton: true,
689689
})
690690
}
691691

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,9 @@ export class Messenger {
488488
this.dispatcher.sendCommandMessage(new SendCommandMessage(message.command, message.tabID, message.eventId))
489489
}
490490

491-
public sendJobFinishedMessage(
492-
tabID: string,
493-
message: string,
494-
includeStartNewTransformationButton: string = 'true'
495-
) {
491+
public sendJobFinishedMessage(tabID: string, message: string, includeStartNewTransformationButton: boolean = true) {
496492
const buttons: ChatItemButton[] = []
497-
if (includeStartNewTransformationButton === 'true') {
493+
if (includeStartNewTransformationButton) {
498494
buttons.push({
499495
keepCardAfterClick: false,
500496
text: CodeWhispererConstants.startTransformationButtonText,

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ export async function postTransformationJob() {
783783
transformByQState.getChatControllers()?.transformationFinished.fire({
784784
message: chatMessage,
785785
tabID: ChatSessionManager.Instance.getSession().tabID,
786-
includeStartNewTransformationButton: 'true',
786+
includeStartNewTransformationButton: true,
787787
})
788788
const durationInMs = calculateTotalLatency(CodeTransformTelemetryState.instance.getStartTime())
789789
const resultStatusMessage = transformByQState.getStatus()

packages/core/src/codewhisperer/models/model.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@ export type SupplementalContextStrategy = CrossFileStrategy | UtgStrategy | 'Emp
5353

5454
export type PatchInfo = {
5555
name: string
56-
fileName: string
56+
filename: string
5757
isSuccessful: boolean
5858
}
5959

60+
export type DescriptionContent = {
61+
content: PatchInfo[]
62+
}
63+
6064
export interface CodeWhispererSupplementalContext {
6165
isUtg: boolean
6266
isProcessTimeout: boolean

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export async function zipCode(
404404
transformByQState.getChatControllers()?.transformationFinished.fire({
405405
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
406406
tabID: ChatSessionManager.Instance.getSession().tabID,
407-
includeStartNewTransformationButton: 'true',
407+
includeStartNewTransformationButton: true,
408408
})
409409
throw new ZipExceedsSizeLimitError()
410410
}

packages/core/src/codewhisperer/service/transformByQ/transformationResultsViewProvider.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { parsePatch, applyPatches, ParsedDiff } from 'diff'
1010
import path from 'path'
1111
import vscode from 'vscode'
1212
import { ExportIntent } from '@amzn/codewhisperer-streaming'
13-
import { TransformByQReviewStatus, transformByQState, PatchInfo } from '../../models/model'
13+
import { TransformByQReviewStatus, transformByQState, PatchInfo, DescriptionContent } from '../../models/model'
1414
import { ExportResultArchiveStructure, downloadExportResultArchive } from '../../../shared/utilities/download'
1515
import { getLogger } from '../../../shared/logger'
1616
import { telemetry } from '../../../shared/telemetry/telemetry'
@@ -111,9 +111,9 @@ export class PatchFileNode {
111111
readonly patchFilePath: string
112112
children: ProposedChangeNode[] = []
113113

114-
constructor(patchFilePath: string) {
114+
constructor(description: PatchInfo | undefined = undefined, patchFilePath: string) {
115115
this.patchFilePath = patchFilePath
116-
this.label = path.basename(patchFilePath)
116+
this.label = description ? description.name : path.basename(patchFilePath)
117117
}
118118
}
119119

@@ -195,7 +195,7 @@ export class DiffModel {
195195
}
196196
},
197197
})
198-
const patchFileNode = new PatchFileNode(diffDescription ? diffDescription.name : pathToDiff)
198+
const patchFileNode = new PatchFileNode(diffDescription, pathToDiff)
199199
patchFileNode.label = `Patch ${this.currentPatchIndex + 1} of ${totalDiffPatches}: ${patchFileNode.label}`
200200
patchFileNode.children = changedFiles.flatMap((file) => {
201201
/* ex. file.oldFileName = 'a/src/java/com/project/component/MyFile.java'
@@ -311,7 +311,8 @@ export class ProposedTransformationExplorer {
311311
})
312312

313313
const patchFiles: string[] = []
314-
let patchFilesDescriptions: PatchInfo[] | undefined = undefined
314+
let singlePatchFile: string = ''
315+
let patchFilesDescriptions: DescriptionContent | undefined = undefined
315316

316317
const reset = async () => {
317318
await setContext('gumby.transformationProposalReviewInProgress', false)
@@ -404,7 +405,7 @@ export class ProposedTransformationExplorer {
404405
transformByQState.getChatControllers()?.transformationFinished.fire({
405406
message: `${CodeWhispererConstants.errorDownloadingDiffChatMessage} The download failed due to: ${downloadErrorMessage}`,
406407
tabID: ChatSessionManager.Instance.getSession().tabID,
407-
includeStartNewTransformationButton: 'true',
408+
includeStartNewTransformationButton: true,
408409
})
409410
await setContext('gumby.reviewState', TransformByQReviewStatus.NotStarted)
410411
getLogger().error(`CodeTransformation: ExportResultArchive error = ${downloadErrorMessage}`)
@@ -424,19 +425,32 @@ export class ProposedTransformationExplorer {
424425
const files = fs.readdirSync(path.join(pathContainingArchive, ExportResultArchiveStructure.PathToPatch))
425426
files.forEach((file) => {
426427
const filePath = path.join(pathContainingArchive, ExportResultArchiveStructure.PathToPatch, file)
427-
if (file.endsWith('.patch')) {
428-
patchFiles.push(filePath)
428+
if (file === 'diff.patch') {
429+
singlePatchFile = filePath
429430
} else if (file.endsWith('.json')) {
430431
const jsonData = fs.readFileSync(filePath, 'utf-8')
431432
patchFilesDescriptions = JSON.parse(jsonData)
432433
}
433434
})
435+
if (patchFilesDescriptions !== undefined) {
436+
for (const patchInfo of patchFilesDescriptions.content) {
437+
patchFiles.push(
438+
path.join(
439+
pathContainingArchive,
440+
ExportResultArchiveStructure.PathToPatch,
441+
patchInfo.filename
442+
)
443+
)
444+
}
445+
} else {
446+
patchFiles.push(singlePatchFile)
447+
}
434448

435449
//Because multiple patches are returned once the ZIP is downloaded, we want to show the first one to start
436450
diffModel.parseDiff(
437451
patchFiles[0],
438452
transformByQState.getProjectPath(),
439-
patchFilesDescriptions ? patchFilesDescriptions[0] : undefined,
453+
patchFilesDescriptions ? patchFilesDescriptions.content[0] : undefined,
440454
patchFiles.length
441455
)
442456

@@ -453,7 +467,7 @@ export class ProposedTransformationExplorer {
453467
transformByQState.getChatControllers()?.transformationFinished.fire({
454468
message: CodeWhispererConstants.viewProposedChangesChatMessage,
455469
tabID: ChatSessionManager.Instance.getSession().tabID,
456-
includeStartNewTransformationButton: 'true',
470+
includeStartNewTransformationButton: true,
457471
})
458472
await vscode.commands.executeCommand('aws.amazonq.transformationHub.summary.reveal')
459473
} catch (e: any) {
@@ -462,7 +476,7 @@ export class ProposedTransformationExplorer {
462476
transformByQState.getChatControllers()?.transformationFinished.fire({
463477
message: `${CodeWhispererConstants.errorDeserializingDiffChatMessage} ${deserializeErrorMessage}`,
464478
tabID: ChatSessionManager.Instance.getSession().tabID,
465-
includeStartNewTransformationButton: 'true',
479+
includeStartNewTransformationButton: true,
466480
})
467481
void vscode.window.showErrorMessage(
468482
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
@@ -484,7 +498,7 @@ export class ProposedTransformationExplorer {
484498
patchFiles.length
485499
),
486500
tabID: ChatSessionManager.Instance.getSession().tabID,
487-
includeStartNewTransformationButton: 'true',
501+
includeStartNewTransformationButton: true,
488502
})
489503
} else {
490504
transformByQState.getChatControllers()?.transformationFinished.fire({
@@ -493,7 +507,7 @@ export class ProposedTransformationExplorer {
493507
patchFiles.length
494508
),
495509
tabID: ChatSessionManager.Instance.getSession().tabID,
496-
includeStartNewTransformationButton: 'false',
510+
includeStartNewTransformationButton: false,
497511
})
498512
}
499513

@@ -502,7 +516,7 @@ export class ProposedTransformationExplorer {
502516
if (diffModel.currentPatchIndex < patchFiles.length) {
503517
const nextPatchFile = patchFiles[diffModel.currentPatchIndex]
504518
const nextPatchFileDescription = patchFilesDescriptions
505-
? patchFilesDescriptions[diffModel.currentPatchIndex]
519+
? patchFilesDescriptions.content[diffModel.currentPatchIndex]
506520
: undefined
507521
diffModel.parseDiff(
508522
nextPatchFile,

0 commit comments

Comments
 (0)