Skip to content

Commit 74b8204

Browse files
author
David Hasani
committed
fix diff.patch issue
1 parent dc291c5 commit 74b8204

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class GumbyController {
224224
this.sessionStorage.getSession().conversationState = ConversationState.WAITING_FOR_TRANSFORMATION_OBJECTIVE
225225
this.messenger.sendStaticTextResponse('choose-transformation-objective', message.tabID)
226226
this.messenger.sendChatInputEnabled(message.tabID, true)
227-
this.messenger.sendUpdatePlaceholder(message.tabID, "Enter 'language upgrade' or 'SQL conversion'")
227+
this.messenger.sendUpdatePlaceholder(message.tabID, CodeWhispererConstants.chooseTransformationObjective)
228228
}
229229

230230
private async beginTransformation(message: any) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class Messenger {
390390
message = 'I will continue transforming your code without upgrading this dependency.'
391391
break
392392
case 'choose-transformation-objective':
393-
message = 'Choose your transformation objective.'
393+
message = CodeWhispererConstants.chooseTransformationObjective
394394
break
395395
}
396396

packages/core/src/amazonqGumby/models/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { TransformationType, transformByQState } from '../../codewhisperer/models/model'
7+
68
// For uniquely identifiying which chat messages should be routed to Gumby
79
export const gumbyChat = 'gumbyChat'
810

911
// This sets the tab name
1012
export const featureName = 'Q - Code Transform'
1113

1214
export const dependencyNoAvailableVersions = 'no available versions'
15+
16+
export function getTransformationActionString() {
17+
return transformByQState.getTransformationType() === TransformationType.LANGUAGE_UPGRADE ? 'upgraded' : 'converted'
18+
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { getTransformationActionString } from '../../amazonqGumby/models/constants'
7+
68
/**
79
* Automated and manual trigger
810
*/
@@ -443,6 +445,8 @@ export const codeTransformLocThreshold = 100000
443445
export const jobStartedChatMessage =
444446
'I am starting to transform your code. It can take 10 to 30 minutes to upgrade your code, depending on the size of your project. To monitor progress, go to the Transformation Hub. If I run into any issues, I might pause the transformation to get input from you on how to proceed.'
445447

448+
export const chooseTransformationObjective = 'Enter "language upgrade" or "sql conversion"'
449+
446450
export const uploadingCodeStepMessage = 'Upload your code'
447451

448452
export const buildCodeStepMessage = 'Build uploaded code in secure build environment'
@@ -483,8 +487,7 @@ export const startTransformationButtonText = 'Start a new transformation'
483487

484488
export const stopTransformationButtonText = 'Stop transformation'
485489

486-
export const checkingForProjectsChatMessage =
487-
'I am checking for open projects that are eligible for Code Transformation.'
490+
export const checkingForProjectsChatMessage = 'Checking for eligible projects...'
488491

489492
export const buildStartedChatMessage =
490493
'I am building your project. This can take up to 10 minutes, depending on the size of your project.'
@@ -571,17 +574,13 @@ export const jobCancelledChatMessage =
571574

572575
export const jobCancelledNotification = 'You cancelled the transformation.'
573576

574-
export const jobCompletedChatMessage =
575-
'I upgraded your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated.'
577+
export const jobCompletedChatMessage = `I ${getTransformationActionString()} your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated.`
576578

577-
export const jobCompletedNotification =
578-
'Amazon Q upgraded your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated.'
579+
export const jobCompletedNotification = `Amazon Q ${getTransformationActionString()} your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated.`
579580

580-
export const jobPartiallyCompletedChatMessage =
581-
'I upgraded part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.'
581+
export const jobPartiallyCompletedChatMessage = `I ${getTransformationActionString()} part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.`
582582

583-
export const jobPartiallyCompletedNotification =
584-
'Amazon Q upgraded part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.'
583+
export const jobPartiallyCompletedNotification = `Amazon Q ${getTransformationActionString()} part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.`
585584

586585
export const noPomXmlFoundChatMessage = `Sorry, I couldn\'t find a project that I can upgrade. I couldn\'t find a pom.xml file in any of your open projects. Currently, I can only upgrade Java 8 or Java 11 projects built on Maven. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
587586

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,25 @@ export class ProposedTransformationExplorer {
372372
pathContainingArchive = path.dirname(pathToArchive)
373373
const zip = new AdmZip(pathToArchive)
374374
zip.extractAllTo(pathContainingArchive)
375+
// TODO: below only needed if the backend cannot fix the "b/" diff.patch issue
376+
// read in the diff.patch
377+
const diffPatch = fs.readFileSync(
378+
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
379+
'utf-8'
380+
)
381+
// go through each line, and replace "b" with "b/" on lines that start with "diff"
382+
const lines = diffPatch.split('\n')
383+
const newLines = lines.map((line) => {
384+
if (line.trim().startsWith('diff') || line.trim().startsWith('+++')) {
385+
return line.replace('b', 'b/')
386+
}
387+
return line
388+
})
389+
const newDiffPatch = newLines.join('\n')
390+
fs.writeFileSync(
391+
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
392+
newDiffPatch
393+
)
375394
diffModel.parseDiff(
376395
path.join(pathContainingArchive, ExportResultArchiveStructure.PathToDiffPatch),
377396
transformByQState.getProjectPath()

0 commit comments

Comments
 (0)