Skip to content

Commit b578bc0

Browse files
committed
updated json structure based on backend and now collecting patchfiles from json
1 parent e880968 commit b578bc0

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
@@ -408,7 +408,7 @@ export async function zipCode(
408408
transformByQState.getChatControllers()?.transformationFinished.fire({
409409
message: CodeWhispererConstants.projectSizeTooLargeChatMessage,
410410
tabID: ChatSessionManager.Instance.getSession().tabID,
411-
includeStartNewTransformationButton: 'true',
411+
includeStartNewTransformationButton: true,
412412
})
413413
throw new ZipExceedsSizeLimitError()
414414
}

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 { TransformationType, TransformByQReviewStatus, transformByQState } 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'
@@ -112,9 +112,9 @@ export class PatchFileNode {
112112
readonly patchFilePath: string
113113
children: ProposedChangeNode[] = []
114114

115-
constructor(patchFilePath: string) {
115+
constructor(description: PatchInfo | undefined = undefined, patchFilePath: string) {
116116
this.patchFilePath = patchFilePath
117-
this.label = path.basename(patchFilePath)
117+
this.label = description ? description.name : path.basename(patchFilePath)
118118
}
119119
}
120120

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

314314
const patchFiles: string[] = []
315-
let patchFilesDescriptions: PatchInfo[] | undefined = undefined
315+
let singlePatchFile: string = ''
316+
let patchFilesDescriptions: DescriptionContent | undefined = undefined
316317

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

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

@@ -454,7 +468,7 @@ export class ProposedTransformationExplorer {
454468
transformByQState.getChatControllers()?.transformationFinished.fire({
455469
message: CodeWhispererConstants.viewProposedChangesChatMessage,
456470
tabID: ChatSessionManager.Instance.getSession().tabID,
457-
includeStartNewTransformationButton: 'true',
471+
includeStartNewTransformationButton: true,
458472
})
459473
await vscode.commands.executeCommand('aws.amazonq.transformationHub.summary.reveal')
460474
} catch (e: any) {
@@ -463,7 +477,7 @@ export class ProposedTransformationExplorer {
463477
transformByQState.getChatControllers()?.transformationFinished.fire({
464478
message: `${CodeWhispererConstants.errorDeserializingDiffChatMessage} ${deserializeErrorMessage}`,
465479
tabID: ChatSessionManager.Instance.getSession().tabID,
466-
includeStartNewTransformationButton: 'true',
480+
includeStartNewTransformationButton: true,
467481
})
468482
void vscode.window.showErrorMessage(
469483
`${CodeWhispererConstants.errorDeserializingDiffNotification} ${deserializeErrorMessage}`
@@ -512,7 +526,7 @@ export class ProposedTransformationExplorer {
512526
patchFiles.length
513527
),
514528
tabID: ChatSessionManager.Instance.getSession().tabID,
515-
includeStartNewTransformationButton: 'true',
529+
includeStartNewTransformationButton: true,
516530
})
517531
} else {
518532
transformByQState.getChatControllers()?.transformationFinished.fire({
@@ -521,7 +535,7 @@ export class ProposedTransformationExplorer {
521535
patchFiles.length
522536
),
523537
tabID: ChatSessionManager.Instance.getSession().tabID,
524-
includeStartNewTransformationButton: 'false',
538+
includeStartNewTransformationButton: false,
525539
})
526540
}
527541

@@ -530,7 +544,7 @@ export class ProposedTransformationExplorer {
530544
if (diffModel.currentPatchIndex < patchFiles.length) {
531545
const nextPatchFile = patchFiles[diffModel.currentPatchIndex]
532546
const nextPatchFileDescription = patchFilesDescriptions
533-
? patchFilesDescriptions[diffModel.currentPatchIndex]
547+
? patchFilesDescriptions.content[diffModel.currentPatchIndex]
534548
: undefined
535549
diffModel.parseDiff(
536550
nextPatchFile,

0 commit comments

Comments
 (0)